From 9929e956f04534d624b38f389474193bc22a2a6c Mon Sep 17 00:00:00 2001 From: yuyi Date: Fri, 22 Sep 2023 23:00:26 +0800 Subject: [PATCH] parser: fix assigning with in another module sumtypes (#19414) --- vlib/v/parser/containers.v | 1 + .../v/tests/assign_with_in_module_sumtype_test.v | 16 ++++++++++++++++ vlib/v/tests/modules/aa/aa.v | 7 +++++++ 3 files changed, 24 insertions(+) create mode 100644 vlib/v/tests/assign_with_in_module_sumtype_test.v create mode 100644 vlib/v/tests/modules/aa/aa.v diff --git a/vlib/v/parser/containers.v b/vlib/v/parser/containers.v index c1759a71d8a332..9dc0bb46abd74a 100644 --- a/vlib/v/parser/containers.v +++ b/vlib/v/parser/containers.v @@ -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 diff --git a/vlib/v/tests/assign_with_in_module_sumtype_test.v b/vlib/v/tests/assign_with_in_module_sumtype_test.v new file mode 100644 index 00000000000000..84b7abb5b4c295 --- /dev/null +++ b/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 + } +} diff --git a/vlib/v/tests/modules/aa/aa.v b/vlib/v/tests/modules/aa/aa.v new file mode 100644 index 00000000000000..902f9ed0ad1f99 --- /dev/null +++ b/vlib/v/tests/modules/aa/aa.v @@ -0,0 +1,7 @@ +module aa + +pub type MySumType = S1 | S2 + +pub struct S1 {} + +pub struct S2 {}