parser: fix assigning with in another module sumtypes (#19414)

This commit is contained in:
yuyi 2023-09-22 23:00:26 +08:00 committed by GitHub
parent ed42341642
commit 9929e956f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 0 deletions

View File

@ -164,6 +164,7 @@ fn (mut p Parser) array_init(is_option bool) ast.ArrayInit {
}
}
pos := first_pos.extend_with_last_line(last_pos, p.prev_tok.line_nr)
p.expr_mod = ''
return ast.ArrayInit{
is_fixed: is_fixed
has_val: has_val

View File

@ -0,0 +1,16 @@
import aa
fn test_assign_with_in_module_sumtype() {
node := aa.MySumType(aa.S1{})
cond := node in [aa.S1, aa.S2]
mut b := 'b'
mut c := 'c'
if cond {
println('${cond} --- ${b} --- ${c}')
assert '${cond} --- ${b} --- ${c}' == 'true --- b --- c'
} else {
assert false
}
}

View File

@ -0,0 +1,7 @@
module aa
pub type MySumType = S1 | S2
pub struct S1 {}
pub struct S2 {}