mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: fix match for array of reference sumtype (#18487)
This commit is contained in:
parent
7c1ace02f3
commit
958e456790
@ -238,7 +238,7 @@ fn (mut p Parser) match_expr() ast.MatchExpr {
|
||||
&& (((ast.builtin_type_names_matcher.matches(p.tok.lit) || p.tok.lit[0].is_capital())
|
||||
&& p.peek_tok.kind != .lpar) || (p.peek_tok.kind == .dot && p.peek_token(2).lit.len > 0
|
||||
&& p.peek_token(2).lit[0].is_capital()))) || p.is_only_array_type()
|
||||
|| p.tok.kind == .key_fn {
|
||||
|| p.tok.kind == .key_fn || p.peek_token(2).kind == .amp {
|
||||
mut types := []ast.Type{}
|
||||
for {
|
||||
// Sum type match
|
||||
|
14
vlib/v/tests/match_array_of_reference_sumtype_test.v
Normal file
14
vlib/v/tests/match_array_of_reference_sumtype_test.v
Normal file
@ -0,0 +1,14 @@
|
||||
type MySumType = []&MyStructA | []&MyStructB
|
||||
|
||||
struct MyStructA {}
|
||||
|
||||
struct MyStructB {}
|
||||
|
||||
fn test_match_branch_with_array_expression() {
|
||||
t := MySumType([&MyStructA{}, &MyStructA{}])
|
||||
ret := match t {
|
||||
[]&MyStructA { '[]&MyStructA' }
|
||||
[]&MyStructB { '[]&MyStructB' }
|
||||
}
|
||||
assert ret == '[]&MyStructA'
|
||||
}
|
Loading…
Reference in New Issue
Block a user