Skip to content

Commit

Permalink
parser: fix assigning with in another module sumtypes (#19414)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Sep 22, 2023
1 parent ed42341 commit 9929e95
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions vlib/v/parser/containers.v
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions vlib/v/tests/assign_with_in_module_sumtype_test.v
@@ -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
}
}
7 changes: 7 additions & 0 deletions vlib/v/tests/modules/aa/aa.v
@@ -0,0 +1,7 @@
module aa

pub type MySumType = S1 | S2

pub struct S1 {}

pub struct S2 {}

0 comments on commit 9929e95

Please sign in to comment.