diff --git a/src/protocol/tests/parser_binding.rs b/src/protocol/tests/parser_binding.rs index 4aa276e9371a3b41772ecf8e7feb2b99b8c4b935..b097f3e748a6d077357c992b4bcb58d93461783a 100644 --- a/src/protocol/tests/parser_binding.rs +++ b/src/protocol/tests/parser_binding.rs @@ -60,6 +60,48 @@ fn test_incorrect_binding() { }); } +#[test] +fn test_incorrect_binding_variable() { + // Note: if variable already exists then it is interpreted at the binding + // expression as value. So the case where "the variable is already defined" + // results in no binding variable. + + Tester::new_single_source_expect_err("binding var in next scope", " + union Option{ Some(T), None } + func foo() -> bool { + auto opt = Option::Some(false); + if (let Option::Some(var) = opt) { + auto var = true; // should mismatch against binding 'var' + return var; + } + return false; + } + ").error(|e| { e + .assert_num(2) + .assert_msg_has(0, "variable name conflicts") + .assert_occurs_at(0, "var = true;") + .assert_occurs_at(1, "var) = opt"); + }); + + Tester::new_single_source_expect_err("binding var in nested scope", " + union LR{ L(A), R(B) } + func foo() -> u32 { + LR x = LR::L(5); + if (let LR::L(y) = x) { + if (true) { + auto y = 5; + return y; + } + } + } + ").error(|e| { e + .assert_num(2) + .assert_msg_has(0, "variable name conflicts") + .assert_occurs_at(0, "y = 5") + .assert_occurs_at(1, "y) = x"); + }); +} + #[test] fn test_boolean_ops_on_binding() { Tester::new_single_source_expect_ok("apply && to binding result", "