Changeset - b708c094d3a2
[Not reviewed]
0 2 0
MH - 4 years ago 2021-12-20 18:21:27
contact@maxhenger.nl
WIP on fixing select variable introduction
2 files changed with 52 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/protocol/tests/parser_binding.rs
Show inline comments
 
@@ -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<T>{ 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<A, B>{ L(A), R(B) }
 
        func foo() -> u32 {
 
            LR<auto, u32> 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", "
src/protocol/tests/parser_validation.rs
Show inline comments
 
@@ -619,10 +619,19 @@ fn test_correct_select_statement() {
 
fn test_incorrect_select_statement() {
 
    Tester::new_single_source_expect_err(
 
        "outside sync",
 
        "func f() -> u32 { select {} return 0; }"
 
        "primitive f() { select {} }"
 
    ).error(|e| { e
 
        .assert_num(1)
 
        .assert_occurs_at(0, "select")
 
        .assert_msg_has(0, "inside sync blocks");
 
    });
 

	
 
    Tester::new_single_source_expect_ok(
 
        "variable in previous block",
 
        "primitive f() {
 
            channel<u32> tx -> rx;
 
            u32 a = 0; // this one will be shadowed
 
            sync select { auto a = get(rx) -> {} }
 
        }"
 
    );
 
}
 
\ No newline at end of file
0 comments (0 inline, 0 general)