From d696233a892992338f80aee59e6bd349a8731b4c Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Sun, 28 Dec 2025 14:25:34 +0800 Subject: [PATCH] ast,parser: obsolete generic cleanup 2 (followup to #26126) (#26174) --- vlib/v/ast/ast.v | 2 +- vlib/v/ast/table.v | 2 +- vlib/v/parser/fn.v | 4 ++-- vlib/v/parser/parse_type.v | 5 +---- vlib/v/parser/parser.v | 8 +------- vlib/v/parser/tests/generic_symbol_err.out | 2 +- 6 files changed, 7 insertions(+), 16 deletions(-) diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 490ae91dd..8fe26257d 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -903,7 +903,7 @@ pub mut: fn_var_type Type // the fn type, when `is_fn_a_const` or `is_fn_var` is true const_name string // the fully qualified name of the const, i.e. `main.c`, given `const c = abc`, and callexpr: `c()` should_be_skipped bool // true for calls to `[if someflag?]` functions, when there is no `-d someflag` - concrete_types []Type // concrete types, e.g. + concrete_types []Type // concrete types, e.g. [int, string] concrete_list_pos token.Pos raw_concrete_types []Type free_receiver bool // true if the receiver expression needs to be freed diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index f0f3df5b4..afa9120bb 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -84,7 +84,7 @@ pub mut: panic_npanics int cur_fn &FnDecl = unsafe { nil } // previously stored in Checker.cur_fn and Gen.cur_fn cur_lambda &LambdaExpr = unsafe { nil } // current lambda node - cur_concrete_types []Type // current concrete types, e.g. + cur_concrete_types []Type // current concrete types, e.g. [int, string] gostmts int // how many `go` statements there were in the parsed files. // When table.gostmts > 0, __VTHREADS__ is defined, which can be checked with `$if threads {` enum_decls map[string]EnumDecl diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index cc7711ae6..ecb56247b 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -44,8 +44,8 @@ fn (mut p Parser) call_expr(language ast.Language, mod string) ast.CallExpr { mut concrete_types := []ast.Type{} mut concrete_list_pos := p.tok.pos() - if p.tok.kind in [.lt, .lsbr] { - // `foo(10)` + if p.tok.kind == .lsbr { + // `foo[int](10)` p.expr_mod = '' concrete_types = p.parse_concrete_types() concrete_list_pos = concrete_list_pos.extend(p.prev_tok.pos()) diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index 13fb50023..e24893501 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -800,7 +800,7 @@ fn (mut p Parser) parse_any_type(language ast.Language, is_ptr bool, check_dot b if name.len == 1 && name[0].is_capital() { return p.parse_generic_type(name) } - if p.tok.kind in [.lt, .lsbr] && p.tok.is_next_to(p.prev_tok) { + if p.tok.kind == .lsbr && p.tok.is_next_to(p.prev_tok) { return p.parse_generic_inst_type(name, name_pos) } return p.find_type_or_add_placeholder(name, language) @@ -935,9 +935,6 @@ fn (mut p Parser) parse_generic_inst_type(name string, name_pos token.Pos) ast.T p.error('too many levels of Parser.parse_generic_inst_type() calls: ${p.generic_type_level}, probably due to too many layers embedded generic type') return ast.void_type } - if p.tok.kind == .lt { - p.error('The generic symbol `<>` is obsolete, please replace it with `[]`') - } mut bs_name := name mut bs_cname := name start_pos := p.tok.pos() diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index e0fee6ef1..98ec676ff 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -1731,7 +1731,7 @@ fn (mut p Parser) name_expr() ast.Expr { // type cast. TODO: finish // if name in ast.builtin_type_names_to_idx { // handle the easy cases first, then check for an already known V typename, not shadowed by a local variable - if (is_option || p.peek_tok.kind in [.lsbr, .lt, .lpar]) && (is_mod_cast + if (is_option || p.peek_tok.kind in [.lsbr, .lpar]) && (is_mod_cast || is_c_pointer_cast || is_c_type_cast || is_js_cast || is_generic_cast || (language == .v && name != '' && (is_capital_after_last_dot || name[0].is_capital() @@ -2343,9 +2343,6 @@ fn (mut p Parser) dot_expr(left ast.Expr) ast.Expr { fn (mut p Parser) parse_generic_types() ([]ast.Type, []string) { mut types := []ast.Type{} mut param_names := []string{} - if p.tok.kind == .lt { - p.error('The generic symbol `<>` is obsolete, please replace it with `[]`') - } if p.tok.kind != .lsbr { return types, param_names } @@ -2396,9 +2393,6 @@ fn (mut p Parser) parse_generic_types() ([]ast.Type, []string) { fn (mut p Parser) parse_concrete_types() []ast.Type { mut types := []ast.Type{} - if p.tok.kind == .lt { - p.error('The generic symbol `<>` is obsolete, please replace it with `[]`') - } if p.tok.kind != .lsbr { return types } diff --git a/vlib/v/parser/tests/generic_symbol_err.out b/vlib/v/parser/tests/generic_symbol_err.out index d3cfa2e30..58c03827c 100644 --- a/vlib/v/parser/tests/generic_symbol_err.out +++ b/vlib/v/parser/tests/generic_symbol_err.out @@ -1,4 +1,4 @@ -vlib/v/parser/tests/generic_symbol_err.vv:1:13: error: The generic symbol `<>` is obsolete, please replace it with `[]` +vlib/v/parser/tests/generic_symbol_err.vv:1:13: error: unexpected token `<`, expecting `(` 1 | pub fn what1(params ...A) { | ^ 2 | println(params) -- 2.39.5