parser: add a check for known vars in or block (#7094)

pull/7109/head
Swastik Baranwal 2020-12-03 09:16:04 +05:30 committed by GitHub
parent 30da85a4d5
commit c5a7c51dfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -645,7 +645,7 @@ pub fn (mut p Parser) stmt(is_top_level bool) ast.Stmt {
} else if p.peek_tok.kind == .name {
p.error_with_pos('unexpected name `$p.peek_tok.lit`', p.peek_tok.position())
} else if !p.inside_if_expr && !p.inside_match_body && !p.inside_or_expr &&
p.peek_tok.kind in [.rcbr, .eof] {
p.peek_tok.kind in [.rcbr, .eof] && !p.mark_var_as_used(p.tok.lit) {
p.error_with_pos('`$p.tok.lit` evaluated but not used', p.tok.position())
}
}

View File

@ -154,3 +154,13 @@ fn test_nested_optional_with_opt_fn_call_as_last_value() {
// }
// assert e == false
}
fn remove_suffix1(s string) string {
n := s.len
i := s.last_index('.') or { n }
return s[0..i]
}
fn test_var_inside_or_block() {
assert remove_suffix1('Vlang.foo') == 'Vlang'
}