From d0426070d3a33dd157100585613e755ef8eb7798 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sat, 12 Oct 2024 17:29:53 -0300 Subject: [PATCH 1/2] fix --- vlib/v/parser/if_match.v | 12 +++++++++--- vlib/v/tests/fns/static_call_on_match_test.v | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 vlib/v/tests/fns/static_call_on_match_test.v diff --git a/vlib/v/parser/if_match.v b/vlib/v/parser/if_match.v index 01decb7f5d96d6..9f5640093a3c64 100644 --- a/vlib/v/parser/if_match.v +++ b/vlib/v/parser/if_match.v @@ -234,12 +234,18 @@ 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 := if is_option { + p.peek_token(next_next_idx) + } else { + 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 { diff --git a/vlib/v/tests/fns/static_call_on_match_test.v b/vlib/v/tests/fns/static_call_on_match_test.v new file mode 100644 index 00000000000000..276308f3b42a5a --- /dev/null +++ b/vlib/v/tests/fns/static_call_on_match_test.v @@ -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 +} From 0f6772e2797601796b49840061b1847bd50751dc Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sat, 12 Oct 2024 18:45:24 -0300 Subject: [PATCH 2/2] fix --- vlib/v/parser/if_match.v | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/vlib/v/parser/if_match.v b/vlib/v/parser/if_match.v index 9f5640093a3c64..b3ebf616d2e12b 100644 --- a/vlib/v/parser/if_match.v +++ b/vlib/v/parser/if_match.v @@ -235,12 +235,7 @@ fn (mut p Parser) is_match_sumtype_type() bool { 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_idx := if is_option { 3 } else { 2 } - next_next_tok := if is_option { - p.peek_token(next_next_idx) - } else { - p.peek_token(next_next_idx) - } - + 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.kind == .name