@@ -879,3 +879,315 @@ fn test_all_cases_comprehensive() {
879879 "# ;
880880 compile_and_run ( program, & [ ] , & [ ] , false ) ;
881881}
882+
883+ #[ test]
884+ fn test_inline_returns_in_loops ( ) {
885+ let program = r#"
886+ fn main() {
887+ result = loop_returns(3);
888+ print(result);
889+ return;
890+ }
891+
892+ fn loop_returns(n) inline -> 1 {
893+ for i in 0..n {
894+ if i == 1 {
895+ return 100;
896+ }
897+ }
898+ return 200;
899+ }
900+ "# ;
901+ compile_and_run ( program, & [ ] , & [ ] , false ) ;
902+ }
903+
904+ #[ test]
905+ fn test_inline_nested_loops_returns ( ) {
906+ let program = r#"
907+ fn main() {
908+ result = nested_loop_returns(2, 2);
909+ print(result);
910+ return;
911+ }
912+
913+ fn nested_loop_returns(x, y) inline -> 1 {
914+ for i in 0..x {
915+ for j in 0..y {
916+ if i == j {
917+ return 300;
918+ }
919+ }
920+ if i == 1 {
921+ return 400;
922+ }
923+ }
924+ return 500;
925+ }
926+ "# ;
927+ compile_and_run ( program, & [ ] , & [ ] , false ) ;
928+ }
929+
930+ #[ test]
931+ fn test_inline_returns_in_match ( ) {
932+ let program = r#"
933+ fn main() {
934+ result1 = match_returns(0);
935+ result2 = match_returns(1);
936+ result3 = match_returns(5);
937+ print(result1);
938+ print(result2);
939+ print(result3);
940+ return;
941+ }
942+
943+ fn match_returns(x) inline -> 1 {
944+ if x == 0 {
945+ return 100;
946+ }
947+ if x == 1 {
948+ return 200;
949+ }
950+ if x == 2 {
951+ return 250;
952+ }
953+ return 300;
954+ }
955+ "# ;
956+ compile_and_run ( program, & [ ] , & [ ] , false ) ;
957+ }
958+
959+ #[ test]
960+ fn test_inline_multiple_return_values_ssa ( ) {
961+ let program = r#"
962+ fn main() {
963+ a, b = multi_return(1);
964+ print(a);
965+ print(b);
966+ return;
967+ }
968+
969+ fn multi_return(x) inline -> 2 {
970+ if x == 0 {
971+ return 100, 200;
972+ }
973+ return 300, 400;
974+ }
975+ "# ;
976+ compile_and_run ( program, & [ ] , & [ ] , false ) ;
977+ }
978+
979+ #[ test]
980+ fn test_inline_multiple_returns_complex_ssa ( ) {
981+ let program = r#"
982+ fn main() {
983+ a, b, c = complex_multi_return(2);
984+ print(a);
985+ print(b);
986+ print(c);
987+ return;
988+ }
989+
990+ fn complex_multi_return(x) inline -> 3 {
991+ if x == 1 {
992+ if x == 0 {
993+ return 100, 200, 300;
994+ }
995+ return 400, 500, 600;
996+ }
997+ return 700, 800, 900;
998+ }
999+ "# ;
1000+ compile_and_run ( program, & [ ] , & [ ] , false ) ;
1001+ }
1002+
1003+ #[ test]
1004+ fn test_inline_deeply_nested_conditions ( ) {
1005+ let program = r#"
1006+ fn main() {
1007+ result = deeply_nested(2);
1008+ print(result);
1009+ return;
1010+ }
1011+
1012+ fn deeply_nested(x) inline -> 1 {
1013+ if x == 1 {
1014+ if x == 2 {
1015+ if x == 3 {
1016+ if x == 4 {
1017+ return 1000;
1018+ }
1019+ return 2000;
1020+ }
1021+ return 3000;
1022+ }
1023+ return 4000;
1024+ }
1025+ return 5000;
1026+ }
1027+ "# ;
1028+ compile_and_run ( program, & [ ] , & [ ] , false ) ;
1029+ }
1030+
1031+ #[ test]
1032+ fn test_inline_mixed_control_flow_ssa ( ) {
1033+ let program = r#"
1034+ fn main() {
1035+ result = mixed_control_flow(1, 2);
1036+ print(result);
1037+ return;
1038+ }
1039+
1040+ fn mixed_control_flow(x, y) inline -> 1 {
1041+ if x == 1 {
1042+ for i in 0..y {
1043+ if i == 1 {
1044+ return 100;
1045+ }
1046+ }
1047+ match y {
1048+ 2 => { return 200; }
1049+ 1 => { return 150; }
1050+ }
1051+ return 300;
1052+ }
1053+ return 400;
1054+ }
1055+ "# ;
1056+ compile_and_run ( program, & [ ] , & [ ] , false ) ;
1057+ }
1058+
1059+ #[ test]
1060+ fn test_inline_complex_fallthrough_patterns ( ) {
1061+ let program = r#"
1062+ fn main() {
1063+ result1 = complex_fallthrough(0);
1064+ result2 = complex_fallthrough(1);
1065+ result3 = complex_fallthrough(2);
1066+ print(result1);
1067+ print(result2);
1068+ print(result3);
1069+ return;
1070+ }
1071+
1072+ fn complex_fallthrough(x) inline -> 1 {
1073+ if x == 0 {
1074+ if x == 1 { return 100; }
1075+ if x == 0 { return 200; }
1076+ } else {
1077+ if x == 1 {
1078+ if x == 2 { return 300; }
1079+ return 400;
1080+ }
1081+ }
1082+ return 500;
1083+ }
1084+ "# ;
1085+ compile_and_run ( program, & [ ] , & [ ] , false ) ;
1086+ }
1087+
1088+ #[ test]
1089+ fn test_inline_with_inline_calls ( ) {
1090+ let program = r#"
1091+ fn main() {
1092+ result = caller_inline(2);
1093+ print(result);
1094+ return;
1095+ }
1096+
1097+ fn caller_inline(x) inline -> 1 {
1098+ if x == 1 {
1099+ return 100;
1100+ }
1101+ return 200;
1102+ }
1103+ "# ;
1104+ compile_and_run ( program, & [ ] , & [ ] , false ) ;
1105+ }
1106+
1107+ #[ test]
1108+ fn test_inline_early_return_chain ( ) {
1109+ let program = r#"
1110+ fn main() {
1111+ result = early_return_chain(5);
1112+ print(result);
1113+ return;
1114+ }
1115+
1116+ fn early_return_chain(x) inline -> 1 {
1117+ if x == 15 {
1118+ return x * 2;
1119+ }
1120+ if x == 10 {
1121+ return x * 3;
1122+ }
1123+ if x == 5 {
1124+ return x * 4;
1125+ }
1126+ return 0;
1127+ }
1128+ "# ;
1129+ compile_and_run ( program, & [ ] , & [ ] , false ) ;
1130+ }
1131+
1132+ #[ test]
1133+ fn test_inline_non_exhaustive_with_loops ( ) {
1134+ let program = r#"
1135+ fn main() {
1136+ result = non_exhaustive_loops(3);
1137+ print(result);
1138+ return;
1139+ }
1140+
1141+ fn non_exhaustive_loops(n) inline -> 1 {
1142+ if n == 3 {
1143+ for i in 0..n {
1144+ if i == 2 {
1145+ return 600;
1146+ }
1147+ }
1148+ if n == 1 {
1149+ return 700;
1150+ }
1151+ }
1152+ return 800;
1153+ }
1154+ "# ;
1155+ compile_and_run ( program, & [ ] , & [ ] , false ) ;
1156+ }
1157+
1158+ #[ test]
1159+ fn test_inline_asymmetric_branching ( ) {
1160+ let program = r#"
1161+ fn main() {
1162+ result1 = asymmetric(0);
1163+ result2 = asymmetric(1);
1164+ result3 = asymmetric(2);
1165+ print(result1);
1166+ print(result2);
1167+ print(result3);
1168+ return;
1169+ }
1170+
1171+ fn asymmetric(x) inline -> 1 {
1172+ if x == 0 {
1173+ if x == 1 {
1174+ return 900;
1175+ }
1176+ } else {
1177+ if x == 1 {
1178+ if x == 2 {
1179+ if x == 3 {
1180+ return 1000;
1181+ }
1182+ return 1100;
1183+ }
1184+ return 1200;
1185+ } else {
1186+ return 1300;
1187+ }
1188+ }
1189+ return 1400;
1190+ }
1191+ "# ;
1192+ compile_and_run ( program, & [ ] , & [ ] , false ) ;
1193+ }
0 commit comments