diff --git a/crates/mun_codegen/src/snapshots/test__update_operators.snap b/crates/mun_codegen/src/snapshots/test__update_operators.snap index 755459dc9..5d794f463 100644 --- a/crates/mun_codegen/src/snapshots/test__update_operators.snap +++ b/crates/mun_codegen/src/snapshots/test__update_operators.snap @@ -1,6 +1,6 @@ --- source: crates/mun_codegen/src/test.rs -expression: "fn add(a:int, b:int):int {\n let result = a\n result += b\n result\n}\n\nfn subtract(a:int, b:int):int {\n let result = a\n result -= b\n result\n}\n\nfn multiply(a:int, b:int):int {\n let result = a\n result *= b\n result\n}" +expression: "fn add(a:int, b:int):int {\n let result = a\n result += b\n result\n}\n\nfn subtract(a:int, b:int):int {\n let result = a\n result -= b\n result\n}\n\nfn multiply(a:int, b:int):int {\n let result = a\n result *= b\n result\n}\n\nfn divide(a:int, b:int):int {\n let result = a\n result /= b\n result\n}" --- ; ModuleID = 'main.mun' source_filename = "main.mun" @@ -23,3 +23,9 @@ body: ret i64 %mul } +define i64 @divide(i64, i64) { +body: + %div = sdiv i64 %0, %1 + ret i64 %div +} + diff --git a/crates/mun_codegen/src/test.rs b/crates/mun_codegen/src/test.rs index 644ac0c9a..5c61683a6 100644 --- a/crates/mun_codegen/src/test.rs +++ b/crates/mun_codegen/src/test.rs @@ -102,6 +102,12 @@ fn update_operators() { result *= b result } + + fn divide(a:int, b:int):int { + let result = a + result /= b + result + } "#, ); } diff --git a/crates/mun_hir/src/ty/snapshots/tests__update_operators.snap b/crates/mun_hir/src/ty/snapshots/tests__update_operators.snap new file mode 100644 index 000000000..f2f8cdaeb --- /dev/null +++ b/crates/mun_hir/src/ty/snapshots/tests__update_operators.snap @@ -0,0 +1,39 @@ +--- +source: crates/mun_hir/src/ty/tests.rs +expression: "fn foo(a:int, b:float) {\n a += 3;\n a -= 3;\n a *= 3;\n a /= 3;\n b += 3.0;\n b -= 3.0;\n b *= 3.0;\n b /= 3.0;\n a *= 3.0; // mismatched type\n b *= 3; // mismatched type\n}" +--- +[138; 141): mismatched type +[171; 172): mismatched type +[7; 8) 'a': int +[14; 15) 'b': float +[23; 194) '{ ...type }': nothing +[29; 30) 'a': int +[29; 35) 'a += 3': nothing +[34; 35) '3': int +[41; 42) 'a': int +[41; 47) 'a -= 3': nothing +[46; 47) '3': int +[53; 54) 'a': int +[53; 59) 'a *= 3': nothing +[58; 59) '3': int +[65; 66) 'a': int +[65; 71) 'a /= 3': nothing +[70; 71) '3': int +[77; 78) 'b': float +[77; 85) 'b += 3.0': nothing +[82; 85) '3.0': float +[91; 92) 'b': float +[91; 99) 'b -= 3.0': nothing +[96; 99) '3.0': float +[105; 106) 'b': float +[105; 113) 'b *= 3.0': nothing +[110; 113) '3.0': float +[119; 120) 'b': float +[119; 127) 'b /= 3.0': nothing +[124; 127) '3.0': float +[133; 134) 'a': int +[133; 141) 'a *= 3.0': nothing +[138; 141) '3.0': int +[166; 167) 'b': float +[166; 172) 'b *= 3': nothing +[171; 172) '3': float diff --git a/crates/mun_hir/src/ty/tests.rs b/crates/mun_hir/src/ty/tests.rs index 793f82c51..f95142016 100644 --- a/crates/mun_hir/src/ty/tests.rs +++ b/crates/mun_hir/src/ty/tests.rs @@ -63,6 +63,26 @@ fn place_expressions() { ) } +#[test] +fn update_operators() { + infer_snapshot( + r#" + fn foo(a:int, b:float) { + a += 3; + a -= 3; + a *= 3; + a /= 3; + b += 3.0; + b -= 3.0; + b *= 3.0; + b /= 3.0; + a *= 3.0; // mismatched type + b *= 3; // mismatched type + } + "#, + ) +} + fn infer_snapshot(text: &str) { let text = text.trim().replace("\n ", "\n"); insta::assert_snapshot!(insta::_macro_support::AutoName, infer(&text), &text);