mirror of
https://github.com/vlang/v.git
synced 2025-09-16 02:49:31 -04:00
parser: allow static method call on match branch (#22507)
This commit is contained in:
parent
da3112e545
commit
6064c6f210
@ -234,12 +234,13 @@ fn (mut p Parser) is_match_sumtype_type() bool {
|
||||
is_option := p.tok.kind == .question
|
||||
name_tok := if is_option { p.peek_tok } else { p.tok }
|
||||
next_tok_kind := if is_option { p.peek_token(2).kind } else { p.peek_tok.kind }
|
||||
next_next_tok := if is_option { p.peek_token(3) } else { p.peek_token(2) }
|
||||
|
||||
next_next_idx := if is_option { 3 } else { 2 }
|
||||
next_next_tok := p.peek_token(next_next_idx)
|
||||
return name_tok.kind == .name && !(name_tok.lit == 'C' && next_tok_kind == .dot)
|
||||
&& (((ast.builtin_type_names_matcher.matches(name_tok.lit) || name_tok.lit[0].is_capital())
|
||||
&& next_tok_kind != .lpar) || (next_tok_kind == .dot && next_next_tok.lit.len > 0
|
||||
&& next_next_tok.lit[0].is_capital()))
|
||||
&& next_tok_kind != .lpar && !(next_tok_kind == .dot && next_next_tok.kind == .name
|
||||
&& p.peek_token(next_next_idx + 1).kind == .lpar)) || (next_tok_kind == .dot
|
||||
&& next_next_tok.lit.len > 0 && next_next_tok.lit[0].is_capital()))
|
||||
}
|
||||
|
||||
fn (mut p Parser) match_expr() ast.MatchExpr {
|
||||
|
17
vlib/v/tests/fns/static_call_on_match_test.v
Normal file
17
vlib/v/tests/fns/static_call_on_match_test.v
Normal file
@ -0,0 +1,17 @@
|
||||
struct User {}
|
||||
|
||||
fn User.is_ok() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
a := match true {
|
||||
User.is_ok() {
|
||||
1
|
||||
}
|
||||
else {
|
||||
2
|
||||
}
|
||||
}
|
||||
assert a == 1
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user