From 67f2e9331db9f34e69d82edb43e7c4dd1d0825c2 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sat, 19 Oct 2024 20:20:42 -0300 Subject: [PATCH] v: fix aliased type checking, add error for passing aliased `int` values to fns that accept `u8` (fix #18278) (#22572) --- .github/workflows/compare_pr_to_master.v | 20 +++++---- vlib/term/termios/termios_darwin.c.v | 2 +- vlib/term/ui/termios_nix.c.v | 2 +- vlib/v/ast/table.v | 26 +++++++---- vlib/v/ast/types.v | 6 +++ vlib/v/checker/assign.v | 6 +-- vlib/v/checker/check_types.v | 43 +++++++++++-------- vlib/v/checker/checker.v | 10 ++--- vlib/v/checker/comptime.v | 14 +++--- vlib/v/checker/fn.v | 10 ++--- vlib/v/checker/infix.v | 8 ++-- vlib/v/checker/orm.v | 4 +- vlib/v/checker/struct.v | 4 +- .../tests/fn_call_mismatch_alias_type_err.out | 6 +++ .../tests/fn_call_mismatch_alias_type_err.vv | 16 +++++++ vlib/v/gen/c/array.v | 2 +- vlib/v/gen/c/cgen.v | 30 ++++++------- vlib/v/gen/c/comptime.v | 16 +++---- vlib/v/gen/c/dumpexpr.v | 10 ++--- vlib/v/gen/c/fn.v | 2 +- vlib/v/gen/c/json.v | 4 +- vlib/v/gen/c/orm.v | 6 +-- vlib/v/gen/c/utils.v | 2 +- vlib/v/gen/js/js.v | 2 +- vlib/v/gen/js/util.v | 4 +- vlib/v/gen/native/amd64.v | 2 +- vlib/v/gen/native/gen.v | 4 +- vlib/v/markused/markused.v | 4 +- vlib/v/parser/comptime.v | 12 +++--- vlib/v/parser/parser.v | 2 +- vlib/v/transformer/transformer.v | 2 +- 31 files changed, 163 insertions(+), 118 deletions(-) create mode 100644 vlib/v/checker/tests/fn_call_mismatch_alias_type_err.out create mode 100644 vlib/v/checker/tests/fn_call_mismatch_alias_type_err.vv diff --git a/.github/workflows/compare_pr_to_master.v b/.github/workflows/compare_pr_to_master.v index 0d48b09b4..83af18d62 100755 --- a/.github/workflows/compare_pr_to_master.v +++ b/.github/workflows/compare_pr_to_master.v @@ -4,11 +4,11 @@ import time const compare_prod = '-prod' in os.args fn gbranch() string { - return os.execute(r'git branch --list|grep ^\*').output.trim_space() + return os.execute(r'git branch --list|grep ^\*').output.trim_left('* ').trim_space() } fn gcommit() string { - return os.execute(r'git rev-parse --short=7 HEAD').output.trim_space() + return os.execute(r'git rev-parse --short=7 HEAD').output.trim_left('* ').trim_space() } fn r(cmd string) { @@ -40,9 +40,10 @@ fn vcompare(vold string, vnew string) { fn main() { // The starting point, when this program should be started, is just after `gh pr checkout NUMBER`. - - println('Current git branch: ${gbranch()}, commit: ${gcommit()}') - println(' Compiling new V executables from PR branch: ${gbranch()}, commit: ${gcommit()} ...') + pr_branch := gbranch() + println('Current git branch: ${pr_branch}, commit: ${gcommit()}') + println(' Compiling new V executables from PR branch: ${pr_branch}, commit: ${gcommit()} ...') + xtime('./v -g self') xtime('./v -o vnew1 cmd/v') xtime('./vnew1 -o vnew2 cmd/v') xtime('./vnew2 -o vnew cmd/v') @@ -52,8 +53,9 @@ fn main() { } r('git checkout master') - - println(' Compiling old V executables from branch: ${gbranch()}, commit: ${gcommit()} ...') + master_branch := gbranch() + println(' Compiling old V executables from branch: ${master_branch}, commit: ${gcommit()} ...') + xtime('./v -g self') xtime('./v -o vold1 cmd/v') xtime('./vold1 -o vold2 cmd/v') xtime('./vold2 -o vold cmd/v') @@ -62,9 +64,9 @@ fn main() { xtime('./vold -prod -o vold_prod cmd/v') } - r('git switch -') // we are on the PR branch again + r('git checkout ${pr_branch}') // we are on the PR branch again - println(' Measuring at PR branch: ${gbranch()}, commit: ${gcommit()} ...') + println(' Measuring at PR branch: ${pr_branch}, commit: ${gcommit()} ...') if compare_prod { vcompare('./vold_prod', './vnew_prod') } else { diff --git a/vlib/term/termios/termios_darwin.c.v b/vlib/term/termios/termios_darwin.c.v index 630c2c1ef..2d7a11dd8 100644 --- a/vlib/term/termios/termios_darwin.c.v +++ b/vlib/term/termios/termios_darwin.c.v @@ -94,5 +94,5 @@ pub fn set_state(fd int, new_state Termios) int { // disable_echo disables echoing characters as they are typed, // when that Termios state is later set with termios.set_state(fd,t) pub fn (mut t Termios) disable_echo() { - t.c_lflag &= invert(C.ECHO) + t.c_lflag &= invert(usize(C.ECHO)) } diff --git a/vlib/term/ui/termios_nix.c.v b/vlib/term/ui/termios_nix.c.v index 77c4f7fcb..8356b19b2 100644 --- a/vlib/term/ui/termios_nix.c.v +++ b/vlib/term/ui/termios_nix.c.v @@ -26,7 +26,7 @@ fn get_termios() termios.Termios { @[inline] fn get_terminal_size() (u16, u16) { winsz := C.winsize{} - termios.ioctl(0, termios.flag(C.TIOCGWINSZ), voidptr(&winsz)) + termios.ioctl(0, u64(termios.flag(C.TIOCGWINSZ)), voidptr(&winsz)) return winsz.ws_row, winsz.ws_col } diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index 62442c84f..82a12afd8 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -649,6 +649,11 @@ pub fn (t &Table) resolve_common_sumtype_fields(mut sym TypeSymbol) { sym.info = info } +@[inline] +pub fn (t &Table) find_type(name string) Type { + return idx_to_type(t.type_idxs[name]) +} + @[inline] pub fn (t &Table) find_type_idx(name string) int { return t.type_idxs[name] @@ -1162,7 +1167,8 @@ pub fn (mut t Table) find_or_register_array_with_dims(elem_type Type, nr_dims in if nr_dims == 1 { return t.find_or_register_array(elem_type) } - return t.find_or_register_array(t.find_or_register_array_with_dims(elem_type, nr_dims - 1)) + return t.find_or_register_array(idx_to_type(t.find_or_register_array_with_dims(elem_type, + nr_dims - 1))) } pub fn (mut t Table) find_or_register_array_fixed(elem_type Type, size int, size_expr Expr, is_fn_ret bool) int { @@ -1416,10 +1422,11 @@ pub fn (t &Table) is_interface_smartcast(var ScopeObject) bool { pub fn (t &Table) known_type_names() []string { mut res := []string{cap: t.type_idxs.len} for _, idx in t.type_idxs { + typ := idx_to_type(idx) // Skip `int_literal_type_idx` and `float_literal_type_idx` because they shouldn't be visible to the User. - if idx !in [0, int_literal_type_idx, float_literal_type_idx] && t.known_type_idx(idx) - && t.sym(idx).kind != .function { - res << t.type_to_str(idx) + if idx !in [0, int_literal_type_idx, float_literal_type_idx] && t.known_type_idx(typ) + && t.sym(typ).kind != .function { + res << t.type_to_str(typ) } } return res @@ -1449,6 +1456,7 @@ pub fn (mut t Table) complete_interface_check() { util.timing_measure(@METHOD) } for tk, mut tsym in t.type_symbols { + tk_typ := idx_to_type(tk) if tsym.kind != .struct { continue } @@ -1460,11 +1468,11 @@ pub fn (mut t Table) complete_interface_check() { if idecl.methods.len == 0 && idecl.fields.len == 0 && tsym.mod != t.sym(idecl.typ).mod { continue } - if t.does_type_implement_interface(tk, idecl.typ) { + if t.does_type_implement_interface(tk_typ, idecl.typ) { $if trace_types_implementing_each_interface ? { eprintln('>>> tsym.mod: ${tsym.mod} | tsym.name: ${tsym.name} | tk: ${tk} | idecl.name: ${idecl.name} | idecl.typ: ${idecl.typ}') } - t.iface_types[idecl.name] << tk + t.iface_types[idecl.name] << tk_typ } } } @@ -1593,7 +1601,7 @@ pub fn (mut t Table) convert_generic_static_type_name(fn_name string, generic_na valid_generic := util.is_generic_type_name(generic_name) && generic_name in generic_names if valid_generic { - name_type := idx_to_type(t.find_type_idx(generic_name)).set_flag(.generic) + name_type := t.find_type(generic_name).set_flag(.generic) if typ := t.convert_generic_type(name_type, generic_names, concrete_types) { return '${t.type_to_str(typ)}${fn_name[index..]}' } @@ -2129,7 +2137,7 @@ pub fn (mut t Table) unwrap_generic_type_ex(typ Type, generic_names []string, co info: info is_pub: ts.is_pub ) - mut ts_copy := t.sym(new_idx) + mut ts_copy := t.sym(idx_to_type(new_idx)) for method in all_methods { ts_copy.register_method(method) } @@ -2585,6 +2593,6 @@ pub fn (mut t Table) get_veb_result_type_idx() int { return t.veb_res_idx_cache } - t.veb_res_idx_cache = t.find_type_idx('veb.Result') + t.veb_res_idx_cache = t.find_type('veb.Result') return t.veb_res_idx_cache } diff --git a/vlib/v/ast/types.v b/vlib/v/ast/types.v index 2c5148df3..271a6fa89 100644 --- a/vlib/v/ast/types.v +++ b/vlib/v/ast/types.v @@ -530,6 +530,12 @@ pub fn (t Type) derive_add_muls(t_from Type) Type { return Type((0xff000000 & t_from) | u16(t)).set_nr_muls(t.nr_muls() + t_from.nr_muls()) } +// return new type from its `idx` +@[inline] +pub fn (t Type) idx_type() Type { + return idx_to_type(t.idx()) +} + // return new type with TypeSymbol idx set to `idx` @[inline] pub fn new_type(idx int) Type { diff --git a/vlib/v/checker/assign.v b/vlib/v/checker/assign.v index 5677bb5bd..8ec4c2b89 100644 --- a/vlib/v/checker/assign.v +++ b/vlib/v/checker/assign.v @@ -717,10 +717,10 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.', modified_left_type := if !left_type.is_int() { c.error('invalid operation: shift on type `${c.table.sym(left_type).name}`', node.pos) - ast.void_type_idx + ast.void_type } else if left_type.is_int_literal() { // int literal => i64 - ast.u32_type_idx + ast.u32_type } else if left_type.is_unsigned() { left_type } else { @@ -731,7 +731,7 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.', // i64 => u64 // isize => usize // i128 => u128 NOT IMPLEMENTED YET - left_type.idx() + ast.u32_type_idx - ast.int_type_idx + ast.idx_to_type(left_type.idx() + ast.u32_type_idx - ast.int_type_idx) } node = ast.AssignStmt{ diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v index f80eb04e1..5cac40ecd 100644 --- a/vlib/v/checker/check_types.v +++ b/vlib/v/checker/check_types.v @@ -208,13 +208,16 @@ fn (c &Checker) check_multiple_ptr_match(got ast.Type, expected ast.Type, param return true } -fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type, language ast.Language, arg ast.CallArg) ! { - if got == 0 { +fn (mut c Checker) check_expected_call_arg(got_ ast.Type, expected_ ast.Type, language ast.Language, arg ast.CallArg) ! { + if got_ == 0 { return error('unexpected 0 type') } - mut expected := expected_ + mut expected := c.table.unaliased_type(expected_) + is_aliased := expected != expected_ + is_exp_sumtype := c.table.type_kind(expected_) == .sum_type + got := c.table.unaliased_type(got_) // variadic - if expected.has_flag(.variadic) { + if expected_.has_flag(.variadic) { exp_type_sym := c.table.sym(expected_) exp_info := exp_type_sym.info as ast.Array expected = exp_info.elem_type @@ -242,7 +245,7 @@ fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type, lan // passing &expr where no-pointer is expected if expected != ast.voidptr_type && !expected.is_ptr() && got.is_ptr() && arg.expr.is_reference() { - got_typ_str, expected_typ_str := c.get_string_names_of(got, expected) + got_typ_str, expected_typ_str := c.get_string_names_of(got_, expected_) return error('cannot use `${got_typ_str}` as `${expected_typ_str}`') } if expected.has_flag(.option) { @@ -250,31 +253,31 @@ fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type, lan || (arg.expr is ast.Ident && (arg.expr as ast.Ident).is_mut()) || arg.expr is ast.None if (expected.is_ptr() && !got_is_ptr) || (!expected.is_ptr() && got.is_ptr()) { - got_typ_str, expected_typ_str := c.get_string_names_of(got, expected) + got_typ_str, expected_typ_str := c.get_string_names_of(got_, expected_) return error('cannot use `${got_typ_str}` as `${expected_typ_str}`') } } // `fn foo(mut p &Expr); mut expr := Expr{}; foo(mut expr)` if arg.is_mut && expected.nr_muls() > 1 && !got.is_ptr() { - got_typ_str, expected_typ_str := c.get_string_names_of(got, expected) + got_typ_str, expected_typ_str := c.get_string_names_of(got_, expected_) return error('cannot use `${got_typ_str}` as `${expected_typ_str}`') } - exp_sym_idx := c.table.sym(expected).idx - got_sym_idx := c.table.sym(got).idx + exp_sym_idx := expected.idx() + got_sym_idx := got.idx() if expected.is_ptr() && got.is_ptr() && exp_sym_idx != got_sym_idx && exp_sym_idx in [ast.u8_type_idx, ast.byteptr_type_idx] && got_sym_idx !in [ast.u8_type_idx, ast.byteptr_type_idx] { - got_typ_str, expected_typ_str := c.get_string_names_of(got, expected) + got_typ_str, expected_typ_str := c.get_string_names_of(got_, expected_) return error('cannot use `${got_typ_str}` as `${expected_typ_str}`') } if !expected.has_flag(.option) && got.has_flag(.option) && (!(arg.expr is ast.Ident || arg.expr is ast.ComptimeSelector) || (arg.expr is ast.Ident && c.comptime.get_ct_type_var(arg.expr) != .field_var)) { - got_typ_str, expected_typ_str := c.get_string_names_of(got, expected) + got_typ_str, expected_typ_str := c.get_string_names_of(got_, expected_) return error('cannot use `${got_typ_str}` as `${expected_typ_str}`, it must be unwrapped first') } } @@ -308,8 +311,12 @@ fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type, lan return } } - - if c.check_types(got, expected) { + exp_type := if !is_aliased || expected_.has_flag(.variadic) { + expected + } else { + expected_ + } + if c.check_types(if is_exp_sumtype { got_ } else { got }, exp_type) { if language == .v && idx_got == ast.voidptr_type_idx { if expected.is_int_valptr() || expected.is_int() || expected.is_ptr() { return @@ -317,7 +324,7 @@ fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type, lan exp_sym := c.table.final_sym(expected) if exp_sym.language == .v && exp_sym.kind !in [.voidptr, .charptr, .byteptr, .function, .placeholder, .array_fixed, .sum_type, .struct] { - got_typ_str, expected_typ_str := c.get_string_names_of(got, expected) + got_typ_str, expected_typ_str := c.get_string_names_of(got_, exp_type) return error('cannot use `${got_typ_str}` as `${expected_typ_str}`') } } @@ -343,7 +350,7 @@ fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type, lan || !c.check_same_module(got, expected) || (!got.is_ptr() && !expected.is_ptr() && got_typ_sym.name != expected_typ_sym.name) { - got_typ_str, expected_typ_str := c.get_string_names_of(got, expected) + got_typ_str, expected_typ_str := c.get_string_names_of(got_, exp_type) return error('cannot use `${got_typ_str}` as `${expected_typ_str}`') } return @@ -351,12 +358,12 @@ fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type, lan if got == ast.void_type { return error('`${arg.expr}` (no value) used as value') } - got_typ_str, expected_typ_str := c.get_string_names_of(got, expected) + got_typ_str, expected_typ_str := c.get_string_names_of(got_, exp_type) return error('cannot use `${got_typ_str}` as `${expected_typ_str}`') } if got != ast.void_type { - got_typ_str, expected_typ_str := c.get_string_names_of(got, expected) + got_typ_str, expected_typ_str := c.get_string_names_of(got_, exp_type) return error('cannot use `${got_typ_str}` as `${expected_typ_str}`') } } @@ -468,7 +475,7 @@ fn (mut c Checker) check_basic(got ast.Type, expected ast.Type) bool { array_info := parent_elem_sym.array_info() elem_type := c.table.find_or_register_array_with_dims(array_info.elem_type, array_info.nr_dims + exp_sym.info.nr_dims) - if c.table.type_to_str(got) == c.table.type_to_str(elem_type) { + if c.table.type_to_str(got) == c.table.type_to_str(ast.idx_to_type(elem_type)) { return true } } diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 507155b63..d93403406 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -1490,7 +1490,7 @@ fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type { valid_generic := util.is_generic_type_name(name) && c.table.cur_fn != unsafe { nil } && name in c.table.cur_fn.generic_names if valid_generic { - name_type = ast.idx_to_type(c.table.find_type_idx(name)).set_flag(.generic) + name_type = c.table.find_type(name).set_flag(.generic) } } ast.TypeOf { @@ -1704,7 +1704,7 @@ fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type { } else { 'wrapping the `${rec_sym.name}` object in a `struct` declared as `@[heap]`' } - c.error('method `${c.table.type_to_str(receiver.idx())}.${method.name}` cannot be used as a variable outside `unsafe` blocks as its receiver might refer to an object stored on stack. Consider ${suggestion}.', + c.error('method `${c.table.type_to_str(receiver.idx_type())}.${method.name}` cannot be used as a variable outside `unsafe` blocks as its receiver might refer to an object stored on stack. Consider ${suggestion}.', node.expr.pos().extend(node.pos)) } } @@ -3142,7 +3142,7 @@ pub fn (mut c Checker) expr(mut node ast.Expr) ast.Type { node.pos) } else if node.stmt != ast.empty_stmt && node.typ == ast.void_type { c.stmt(mut node.stmt) - node.typ = c.table.find_type_idx((node.stmt as ast.StructDecl).name) + node.typ = c.table.find_type((node.stmt as ast.StructDecl).name) } return node.typ } @@ -3494,7 +3494,7 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type { } } else if to_type.is_int() && mut node.expr is ast.IntegerLiteral { tt := c.table.type_to_str(to_type) - tsize, _ := c.table.type_size(to_type.idx()) + tsize, _ := c.table.type_size(to_type.idx_type()) bit_size := tsize * 8 value_string := match node.expr.val[0] { `-`, `+` { @@ -4828,7 +4828,7 @@ fn (mut c Checker) enum_val(mut node ast.EnumVal) ast.Type { // In the checker the name for such enums was set to `main.ChanState` instead of // just `ChanState`. if node.enum_name.starts_with('${c.mod}.') { - typ_idx = c.table.find_type_idx(node.enum_name['${c.mod}.'.len..]) + typ_idx = c.table.find_type(node.enum_name['${c.mod}.'.len..]) if typ_idx == 0 { c.error('unknown enum `${node.enum_name}` (type_idx=0)', node.pos) return ast.void_type diff --git a/vlib/v/checker/comptime.v b/vlib/v/checker/comptime.v index 0a254bf0a..9ce43873d 100644 --- a/vlib/v/checker/comptime.v +++ b/vlib/v/checker/comptime.v @@ -88,7 +88,7 @@ fn (mut c Checker) comptime_call(mut node ast.ComptimeCall) ast.Type { c.error('not supported compression type: .${node.embed_file.compression_type}. supported: ${supported}', node.pos) } - return c.table.find_type_idx('v.embed_file.EmbedFileData') + return c.table.find_type('v.embed_file.EmbedFileData') } if node.is_vweb { // TODO: assoc parser bug @@ -118,9 +118,9 @@ fn (mut c Checker) comptime_call(mut node ast.ComptimeCall) ast.Type { node.pos) } rtyp := if node.is_veb { - c.table.find_type_idx('veb.Result') + c.table.find_type('veb.Result') } else { - c.table.find_type_idx('vweb.Result') + c.table.find_type('vweb.Result') } node.result_type = rtyp return rtyp @@ -265,7 +265,7 @@ fn (mut c Checker) comptime_for(mut node ast.ComptimeFor) { c.push_new_comptime_info() c.comptime.inside_comptime_for = true if c.field_data_type == 0 { - c.field_data_type = ast.idx_to_type(c.table.find_type_idx('FieldData')) + c.field_data_type = c.table.find_type('FieldData') } c.comptime.comptime_for_field_value = field c.comptime.comptime_for_field_var = node.val_var @@ -298,7 +298,7 @@ fn (mut c Checker) comptime_for(mut node ast.ComptimeFor) { c.push_new_comptime_info() c.comptime.inside_comptime_for = true if c.enum_data_type == 0 { - c.enum_data_type = ast.idx_to_type(c.table.find_type_idx('EnumData')) + c.enum_data_type = c.table.find_type('EnumData') } c.comptime.comptime_for_enum_var = node.val_var c.comptime.type_map[node.val_var] = c.enum_data_type @@ -338,7 +338,7 @@ fn (mut c Checker) comptime_for(mut node ast.ComptimeFor) { c.pop_comptime_info() } else if node.kind == .variants { if c.variant_data_type == 0 { - c.variant_data_type = ast.idx_to_type(c.table.find_type_idx('VariantData')) + c.variant_data_type = c.table.find_type('VariantData') } mut variants := []ast.Type{} if c.comptime.comptime_for_field_var != '' && typ == c.field_data_type { @@ -628,7 +628,7 @@ fn (mut c Checker) verify_all_vweb_routes() { return } c.table.used_veb_types = c.vweb_gen_types - typ_vweb_result := c.table.find_type_idx('vweb.Result') + typ_vweb_result := c.table.find_type('vweb.Result') old_file := c.file for vgt in c.vweb_gen_types { sym_app := c.table.sym(vgt) diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 6753cf892..b41cbf0f6 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -19,7 +19,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) { } // record the veb route methods (public non-generic methods): if node.generic_names.len > 0 && node.is_pub { - typ_vweb_result := c.table.find_type_idx('veb.Result') + typ_vweb_result := c.table.find_type('veb.Result') if node.return_type == typ_vweb_result { rec_sym := c.table.sym(node.receiver.typ) if rec_sym.kind == .struct { @@ -452,15 +452,15 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) { } c.fn_scope = node.scope // Register implicit context var - typ_veb_result := c.table.get_veb_result_type_idx() // c.table.find_type_idx('veb.Result') + typ_veb_result := c.table.get_veb_result_type_idx() // c.table.find_type('veb.Result') if node.return_type == typ_veb_result { // Find a custom user Context type first - mut ctx_idx := c.table.find_type_idx('main.Context') + mut ctx_idx := c.table.find_type('main.Context') if ctx_idx < 1 { // If it doesn't exist, use veb.Context - ctx_idx = c.table.find_type_idx('veb.Context') + ctx_idx = c.table.find_type('veb.Context') } - typ_veb_context := ast.Type(u32(ctx_idx)).set_nr_muls(1) + typ_veb_context := ctx_idx.set_nr_muls(1) // No `ctx` param? Add it if !node.params.any(it.name == 'ctx') && node.params.len >= 1 { params := node.params.clone() diff --git a/vlib/v/checker/infix.v b/vlib/v/checker/infix.v index fa38ce6ad..6a7a8f5c4 100644 --- a/vlib/v/checker/infix.v +++ b/vlib/v/checker/infix.v @@ -676,10 +676,10 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type { modified_left_type := if !left_type.is_int() { c.error('invalid operation: shift on type `${c.table.sym(left_type).name}`', left_pos) - ast.void_type_idx + ast.void_type } else if left_type.is_int_literal() { // int literal => i64 - ast.u32_type_idx + ast.u32_type } else if left_type.is_unsigned() { left_type } else { @@ -690,7 +690,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type { // i64 => u64 // isize => usize // i128 => u128 NOT IMPLEMENTED YET - match left_type.idx() { + ast.idx_to_type(match left_type.idx() { ast.i8_type_idx { ast.u8_type_idx } ast.i16_type_idx { ast.u16_type_idx } ast.i32_type_idx { ast.u32_type_idx } @@ -698,7 +698,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type { ast.i64_type_idx { ast.u64_type_idx } ast.isize_type_idx { ast.usize_type_idx } else { 0 } - } + }) } if modified_left_type == 0 { diff --git a/vlib/v/checker/orm.v b/vlib/v/checker/orm.v index 462ec75a8..06b6f44fc 100644 --- a/vlib/v/checker/orm.v +++ b/vlib/v/checker/orm.v @@ -636,8 +636,8 @@ fn (mut c Checker) check_orm_or_expr(mut expr ORMExpr) { // check_db_expr checks the `db_expr` implements `orm.Connection` and has no `option` flag. fn (mut c Checker) check_db_expr(mut db_expr ast.Expr) bool { - connection_type_index := c.table.find_type_idx('orm.Connection') - connection_typ := ast.idx_to_type(connection_type_index) + connection_type_index := c.table.find_type('orm.Connection') + connection_typ := connection_type_index db_expr_type := c.expr(mut db_expr) // If we didn't find `orm.Connection`, we don't have any imported modules diff --git a/vlib/v/checker/struct.v b/vlib/v/checker/struct.v index 22dc5d334..0477e0d7a 100644 --- a/vlib/v/checker/struct.v +++ b/vlib/v/checker/struct.v @@ -341,7 +341,7 @@ fn (mut c Checker) struct_decl(mut node ast.StructDecl) { if node.is_implements { // XTODO2 // cgen error if I use `println(sym)` without handling the option with `or{}` - struct_type := c.table.find_type_idx(node.name) // or { panic(err) } + struct_type := c.table.find_type(node.name) // or { panic(err) } mut names_used := []string{} for t in node.implements_types { t_sym := c.table.sym(t.typ) @@ -935,7 +935,7 @@ fn (mut c Checker) check_uninitialized_struct_fields_and_embeds(node ast.StructI if field.has_default_expr { if i < info.fields.len && field.default_expr_typ == 0 { if mut field.default_expr is ast.StructInit { - idx := c.table.find_type_idx(field.default_expr.typ_str) + idx := c.table.find_type(field.default_expr.typ_str) if idx != 0 { info.fields[i].default_expr_typ = ast.new_type(idx) } diff --git a/vlib/v/checker/tests/fn_call_mismatch_alias_type_err.out b/vlib/v/checker/tests/fn_call_mismatch_alias_type_err.out new file mode 100644 index 000000000..d8561e46c --- /dev/null +++ b/vlib/v/checker/tests/fn_call_mismatch_alias_type_err.out @@ -0,0 +1,6 @@ +vlib/v/checker/tests/fn_call_mismatch_alias_type_err.vv:15:10: error: cannot use `Int` as `u8` in argument 1 to `take_u8` + 13 | value: 10000 + 14 | } + 15 | take_u8(foo.value) + | ~~~~~~~~~ + 16 | } diff --git a/vlib/v/checker/tests/fn_call_mismatch_alias_type_err.vv b/vlib/v/checker/tests/fn_call_mismatch_alias_type_err.vv new file mode 100644 index 000000000..f5fb869d1 --- /dev/null +++ b/vlib/v/checker/tests/fn_call_mismatch_alias_type_err.vv @@ -0,0 +1,16 @@ +type Int = int + +struct Foo { + value Int +} + +fn take_u8(u u8) { + println(u) +} + +fn main() { + foo := Foo{ + value: 10000 + } + take_u8(foo.value) +} diff --git a/vlib/v/gen/c/array.v b/vlib/v/gen/c/array.v index 0d9afed5d..b21debebe 100644 --- a/vlib/v/gen/c/array.v +++ b/vlib/v/gen/c/array.v @@ -941,7 +941,7 @@ fn (mut g Gen) gen_array_prepend(node ast.CallExpr) { fn (mut g Gen) get_array_contains_method(typ ast.Type) string { t := g.table.final_sym(g.unwrap_generic(typ).set_nr_muls(0)).idx g.array_contains_types << t - return g.typ(t) + '_contains' + return g.typ(ast.idx_to_type(t)) + '_contains' } fn (mut g Gen) gen_array_contains_methods() { diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index d1735000a..e3d7c0b2e 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -245,8 +245,8 @@ mut: cur_fn &ast.FnDecl = unsafe { nil } // same here cur_lock ast.LockExpr cur_struct_init_typ ast.Type - autofree_methods map[int]bool - generated_free_methods map[int]bool + autofree_methods map[ast.Type]bool + generated_free_methods map[ast.Type]bool autofree_scope_stmts []string use_segfault_handler bool = true test_function_names []string @@ -329,9 +329,9 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) (str label: 'global_cgen' ) inner_loop: unsafe { &ast.empty_stmt } - field_data_type: ast.idx_to_type(table.find_type_idx('FieldData')) - enum_data_type: ast.idx_to_type(table.find_type_idx('EnumData')) - variant_data_type: ast.idx_to_type(table.find_type_idx('VariantData')) + field_data_type: table.find_type('FieldData') + enum_data_type: table.find_type('EnumData') + variant_data_type: table.find_type('VariantData') is_cc_msvc: pref_.ccompiler == 'msvc' use_segfault_handler: !('no_segfault_handler' in pref_.compile_defines || pref_.os in [.wasm32, .wasm32_emscripten]) @@ -719,8 +719,8 @@ fn cgen_process_one_file_cb(mut p pool.PoolProcessor, idx int, wid int) &Gen { label: 'cgen_process_one_file_cb idx: ${idx}, wid: ${wid}' ) inner_loop: &ast.empty_stmt - field_data_type: ast.idx_to_type(global_g.table.find_type_idx('FieldData')) - enum_data_type: ast.idx_to_type(global_g.table.find_type_idx('EnumData')) + field_data_type: global_g.table.find_type('FieldData') + enum_data_type: global_g.table.find_type('EnumData') array_sort_fn: global_g.array_sort_fn waiter_fns: global_g.waiter_fns threaded_fns: global_g.threaded_fns @@ -2429,7 +2429,7 @@ struct SumtypeCastingFn { } fn (mut g Gen) get_sumtype_casting_fn(got_ ast.Type, exp_ ast.Type) string { - mut got, exp := got_.idx(), exp_.idx() + mut got, exp := got_.idx_type(), exp_.idx_type() i := got | int(u32(exp) << 17) | int(u32(exp_.has_flag(.option)) << 16) exp_sym := g.table.sym(exp) mut got_sym := g.table.sym(got) @@ -2444,7 +2444,7 @@ fn (mut g Gen) get_sumtype_casting_fn(got_ ast.Type, exp_ ast.Type) string { return fn_name } for got_sym.parent_idx != 0 && got_sym.idx !in (exp_sym.info as ast.SumType).variants { - got_sym = g.table.sym(got_sym.parent_idx) + got_sym = g.table.sym(ast.idx_to_type(got_sym.parent_idx)) } g.sumtype_definitions[i] = true g.sumtype_casting_fns << SumtypeCastingFn{ @@ -2456,7 +2456,7 @@ fn (mut g Gen) get_sumtype_casting_fn(got_ ast.Type, exp_ ast.Type) string { got_sym.idx } exp: if exp_.has_flag(.option) { - new_exp := ast.idx_to_type(exp).set_flag(.option) + new_exp := exp.set_flag(.option) new_exp } else { exp @@ -4057,13 +4057,13 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) { left_type_name := util.no_dots(left_cc_type) g.write('${c_name(left_type_name)}_name_table[${node.expr.name}${g.dot_or_ptr(node.expr_type)}_typ]._method_${m.name}') } else { - g.write('${g.typ(node.expr_type.idx())}_${m.name}') + g.write('${g.typ(node.expr_type.idx_type())}_${m.name}') } return } receiver := m.params[0] - expr_styp := g.typ(node.expr_type.idx()) - data_styp := g.typ(receiver.typ.idx()) + expr_styp := g.typ(node.expr_type.idx_type()) + data_styp := g.typ(receiver.typ.idx_type()) mut sb := strings.new_builder(256) name := '_V_closure_${expr_styp}_${m.name}_${node.pos.pos}' sb.write_string('${g.typ(m.return_type)} ${name}(') @@ -6819,7 +6819,7 @@ fn (mut g Gen) write_types(symbols []&ast.TypeSymbol) { if variant in idxs { continue } - g.type_definitions.writeln('// | ${variant:4d} = ${g.typ(variant.idx()):-20s}') + g.type_definitions.writeln('// | ${variant:4d} = ${g.typ(variant.idx_type()):-20s}') idxs << variant } idxs.clear() @@ -8030,7 +8030,7 @@ static inline __shared__${interface_name} ${shared_fn_name}(__shared__${cctype}* } } for vtyp, variants in inter_info.conversions { - vsym := g.table.sym(vtyp) + vsym := g.table.sym(ast.idx_to_type(vtyp)) if variants.len > 0 { conversion_functions.write_string('static inline bool I_${interface_name}_is_I_${vsym.cname}(${interface_name} x) {\n\treturn ') diff --git a/vlib/v/gen/c/comptime.v b/vlib/v/gen/c/comptime.v index 9cf381769..d82aae9ba 100644 --- a/vlib/v/gen/c/comptime.v +++ b/vlib/v/gen/c/comptime.v @@ -591,10 +591,10 @@ fn (mut g Gen) comptime_if_cond(cond ast.Expr, pkg_exist bool) (bool, bool) { return !is_compatible, true } } else if cond.op == .key_is { - g.write('${exp_type.idx()} == ${got_type.idx()} && ${exp_type.has_flag(.option)} == ${got_type.has_flag(.option)}') + g.write('${int(exp_type.idx())} == ${int(got_type.idx())} && ${exp_type.has_flag(.option)} == ${got_type.has_flag(.option)}') return exp_type == got_type, true } else { - g.write('${exp_type.idx()} != ${got_type.idx()}') + g.write('${int(exp_type.idx())} != ${int(got_type.idx())}') return exp_type != got_type, true } } @@ -833,7 +833,7 @@ fn (mut g Gen) comptime_for(node ast.ComptimeFor) { if methods.len > 0 { g.writeln('FunctionData ${node.val_var} = {0};') } - typ_vweb_result := g.table.find_type_idx('vweb.Result') + typ_vweb_result := g.table.find_type('vweb.Result') for method in methods { g.push_new_comptime_info() // filter vweb route methods (non-generic method) @@ -893,12 +893,12 @@ fn (mut g Gen) comptime_for(node ast.ComptimeFor) { if ret_type != 'void' { sig += ' ${ret_type}' } - styp := g.table.find_type_idx(sig) + styp := g.table.find_type(sig) // TODO: type aliases ret_typ := method.return_type - g.writeln('\t${node.val_var}.typ = ${styp};') - g.writeln('\t${node.val_var}.return_type = ${ret_typ.idx()};') + g.writeln('\t${node.val_var}.typ = ${int(styp)};') + g.writeln('\t${node.val_var}.return_type = ${int(ret_typ.idx())};') g.comptime.type_map['${node.val_var}.return_type'] = ret_typ g.comptime.type_map['${node.val_var}.typ'] = styp @@ -945,8 +945,8 @@ fn (mut g Gen) comptime_for(node ast.ComptimeFor) { styp := field.typ unaliased_styp := g.table.unaliased_type(styp) - g.writeln('\t${node.val_var}.typ = ${styp.idx()};') - g.writeln('\t${node.val_var}.unaliased_typ = ${unaliased_styp.idx()};') + g.writeln('\t${node.val_var}.typ = ${int(styp.idx())};') + g.writeln('\t${node.val_var}.unaliased_typ = ${int(unaliased_styp.idx())};') g.writeln('\t${node.val_var}.is_pub = ${field.is_pub};') g.writeln('\t${node.val_var}.is_mut = ${field.is_mut};') diff --git a/vlib/v/gen/c/dumpexpr.v b/vlib/v/gen/c/dumpexpr.v index d75ab2153..7ca9e37c2 100644 --- a/vlib/v/gen/c/dumpexpr.v +++ b/vlib/v/gen/c/dumpexpr.v @@ -95,7 +95,7 @@ fn (mut g Gen) dump_expr_definitions() { mut dump_fns := strings.new_builder(100) mut dump_fn_defs := strings.new_builder(100) for dump_type, cname in g.table.dumps { - dump_sym := g.table.sym(dump_type) + dump_sym := g.table.sym(ast.idx_to_type(dump_type)) // eprintln('>>> dump_type: $dump_type | cname: $cname | dump_sym: $dump_sym.name') mut name := cname if dump_sym.language == .c { @@ -104,7 +104,7 @@ fn (mut g Gen) dump_expr_definitions() { _, str_method_expects_ptr, _ := dump_sym.str_method_info() typ := ast.idx_to_type(dump_type) is_ptr := typ.is_ptr() - deref, _ := deref_kind(str_method_expects_ptr, is_ptr, dump_type) + deref, _ := deref_kind(str_method_expects_ptr, is_ptr, typ) to_string_fn_name := g.get_str_fn(typ.clear_flags(.shared_f, .result)) mut ptr_asterisk := if is_ptr { '*'.repeat(typ.nr_muls()) } else { '' } mut str_dumparg_type := '' @@ -116,7 +116,7 @@ fn (mut g Gen) dump_expr_definitions() { str_dumparg_type += '_option_' ptr_asterisk = ptr_asterisk.replace('*', '_ptr') } - str_dumparg_type += g.cc_type(dump_type, true) + ptr_asterisk + str_dumparg_type += g.cc_type(typ, true) + ptr_asterisk } mut is_fixed_arr_ret := false if dump_sym.kind == .function { @@ -182,7 +182,7 @@ fn (mut g Gen) dump_expr_definitions() { '\tstring_free(&value);') } else { prefix := if dump_sym.is_c_struct() { - c_struct_ptr(dump_sym, dump_type, str_method_expects_ptr) + c_struct_ptr(dump_sym, typ, str_method_expects_ptr) } else { deref } @@ -191,7 +191,7 @@ fn (mut g Gen) dump_expr_definitions() { } } else { prefix := if dump_sym.is_c_struct() { - c_struct_ptr(dump_sym, dump_type, str_method_expects_ptr) + c_struct_ptr(dump_sym, typ, str_method_expects_ptr) } else { deref } diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index 140cc87ed..4e3eed6dd 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -730,7 +730,7 @@ fn (mut g Gen) fn_decl_params(params []ast.Param, scope &ast.Scope, is_variadic // Veb actions defined by user can have implicit context /* if g.cur_fn != unsafe { nil } && g.cur_fn.is_method && g.cur_mod.name != 'veb' { - typ_veb_result := g.table.find_type_idx('veb.Result') + typ_veb_result := g.table.find_type('veb.Result') // if params.len == 3 { // println(g.cur_fn) //} diff --git a/vlib/v/gen/c/json.v b/vlib/v/gen/c/json.v index 83f934c81..ba254ac16 100644 --- a/vlib/v/gen/c/json.v +++ b/vlib/v/gen/c/json.v @@ -365,7 +365,7 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st ret_styp string) { info := sym.info as ast.SumType type_var := g.new_tmp_var() - typ := g.table.type_idxs[sym.name] + typ := ast.idx_to_type(g.table.type_idxs[sym.name]) prefix := if utyp.is_ptr() { '*' } else { '' } field_op := if utyp.is_ptr() { '->' } else { '.' } is_option := utyp.has_flag(.option) @@ -419,7 +419,7 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st g.definitions.writeln('static inline ${sym.cname} ${variant_typ}_to_sumtype_${sym.cname}(${variant_typ}* x);') // ENCODING - enc.writeln('\tif (${var_data}${field_op}_typ == ${variant.idx()}) {') + enc.writeln('\tif (${var_data}${field_op}_typ == ${int(variant.idx())}) {') $if json_no_inline_sumtypes ? { if variant_sym.kind == .enum { enc.writeln('\t\tcJSON_AddItemToObject(o, "${unmangled_variant_name}", ${js_enc_name('u64')}(*${var_data}${field_op}_${variant_typ}));') diff --git a/vlib/v/gen/c/orm.v b/vlib/v/gen/c/orm.v index c8800c046..5e024e01d 100644 --- a/vlib/v/gen/c/orm.v +++ b/vlib/v/gen/c/orm.v @@ -516,7 +516,7 @@ fn (mut g Gen) write_orm_insert_with_last_ids(node ast.SqlStmtLine, connection_v fn (mut g Gen) write_orm_expr_to_primitive(expr ast.Expr) { match expr { ast.InfixExpr { - g.write_orm_primitive(g.table.find_type_idx('orm.InfixType'), expr) + g.write_orm_primitive(g.table.find_type('orm.InfixType'), expr) } ast.StringLiteral { g.write_orm_primitive(ast.string_type, expr) @@ -1041,7 +1041,7 @@ fn (mut g Gen) write_orm_select(node ast.SqlExpr, connection_var_name string, re mut sub := node.sub_structs[int(field.typ)] mut where_expr := sub.where_expr as ast.InfixExpr mut ident := where_expr.right as ast.Ident - primitive_type_index := g.table.find_type_idx('orm.Primitive') + primitive_type_index := g.table.find_type('orm.Primitive') if primitive_type_index != 0 { if mut ident.info is ast.IdentVar { @@ -1222,7 +1222,7 @@ fn (g &Gen) get_table_name_by_struct_type(typ ast.Type) string { // get_orm_current_table_field returns the current processing table's struct field by name. fn (g &Gen) get_orm_current_table_field(name string) ?ast.StructField { - info := g.table.sym(g.table.type_idxs[g.sql_table_name]).struct_info() + info := g.table.sym(ast.idx_to_type(g.table.type_idxs[g.sql_table_name])).struct_info() for field in info.fields { if field.name == name { diff --git a/vlib/v/gen/c/utils.v b/vlib/v/gen/c/utils.v index 1786a391b..92981f89b 100644 --- a/vlib/v/gen/c/utils.v +++ b/vlib/v/gen/c/utils.v @@ -79,7 +79,7 @@ fn (mut g Gen) unwrap(typ ast.Type) Type { typ: no_generic sym: no_generic_sym unaliased: no_generic_sym.parent_idx - unaliased_sym: g.table.sym(no_generic_sym.parent_idx) + unaliased_sym: g.table.sym(ast.idx_to_type(no_generic_sym.parent_idx)) } } diff --git a/vlib/v/gen/js/js.v b/vlib/v/gen/js/js.v index 4bd9e4ea2..04b85a266 100644 --- a/vlib/v/gen/js/js.v +++ b/vlib/v/gen/js/js.v @@ -3104,7 +3104,7 @@ fn (mut g JsGen) gen_infix_expr(it ast.InfixExpr) { g.gen_deref_ptr(it.right_type) g.write(')') } else { - mut greater_typ := 0 + mut greater_typ := ast.no_type // todo(playX): looks like this cast is always required to perform .eq operation on types. if is_arithmetic { greater_typ = g.greater_typ(it.left_type, it.right_type) diff --git a/vlib/v/gen/js/util.v b/vlib/v/gen/js/util.v index 3e5021754..a764abe4c 100644 --- a/vlib/v/gen/js/util.v +++ b/vlib/v/gen/js/util.v @@ -29,7 +29,7 @@ fn (mut g JsGen) unwrap(typ ast.Type) Type { return Type{ typ: no_generic sym: no_generic_sym - unaliased: no_generic_sym.parent_idx - unaliased_sym: g.table.sym(no_generic_sym.parent_idx) + unaliased: ast.idx_to_type(no_generic_sym.parent_idx) + unaliased_sym: g.table.sym(ast.idx_to_type(no_generic_sym.parent_idx)) } } diff --git a/vlib/v/gen/native/amd64.v b/vlib/v/gen/native/amd64.v index ae38a9474..e87b54f83 100644 --- a/vlib/v/gen/native/amd64.v +++ b/vlib/v/gen/native/amd64.v @@ -666,7 +666,7 @@ fn (mut c Amd64) mov_reg_to_var(var Var, r Register, config VarConfig) { size_str = 'BYTE' } else { - ts := c.g.table.sym(typ.idx()) + ts := c.g.table.sym(typ.idx_type()) if ts.info is ast.Enum { if is_extended_register { c.g.write8(0x44) diff --git a/vlib/v/gen/native/gen.v b/vlib/v/gen/native/gen.v index 112b629c1..4fc7d65ba 100644 --- a/vlib/v/gen/native/gen.v +++ b/vlib/v/gen/native/gen.v @@ -377,7 +377,7 @@ pub fn macho_test_new_gen(p &pref.Preferences, out_name string) &Gen { return &mut g } -pub fn (mut g Gen) typ(a i32) &ast.TypeSymbol { +pub fn (mut g Gen) typ(a ast.Type) &ast.TypeSymbol { return g.table.type_symbols[a] } @@ -820,7 +820,7 @@ fn (mut g Gen) is_fp_type(typ ast.Type) bool { fn (mut g Gen) get_sizeof_ident(ident ast.Ident) i32 { typ := match ident.obj { - ast.AsmRegister { ast.i64_type_idx } + ast.AsmRegister { ast.i64_type } ast.ConstField { ident.obj.typ } ast.GlobalField { ident.obj.typ } ast.Var { ident.obj.typ } diff --git a/vlib/v/markused/markused.v b/vlib/v/markused/markused.v index a2f15e560..91c60d4d8 100644 --- a/vlib/v/markused/markused.v +++ b/vlib/v/markused/markused.v @@ -444,10 +444,10 @@ fn all_fn_const_and_global(ast_files []&ast.File) (map[string]ast.FnDecl, map[st fn handle_vweb(mut table ast.Table, mut all_fn_root_names []string, result_name string, filter_name string, context_name string) { // handle vweb magic router methods: - result_type_idx := table.find_type_idx(result_name) + result_type_idx := table.find_type(result_name) if result_type_idx != 0 { all_fn_root_names << filter_name - typ_vweb_context := ast.idx_to_type(table.find_type_idx(context_name)).set_nr_muls(1) + typ_vweb_context := table.find_type(context_name).set_nr_muls(1) all_fn_root_names << '${int(typ_vweb_context)}.html' for vgt in table.used_veb_types { sym_app := table.sym(vgt) diff --git a/vlib/v/parser/comptime.v b/vlib/v/parser/comptime.v index 690c6c94a..02ec19196 100644 --- a/vlib/v/parser/comptime.v +++ b/vlib/v/parser/comptime.v @@ -366,7 +366,7 @@ fn (mut p Parser) comptime_for() ast.ComptimeFor { 'params' { p.scope.register(ast.Var{ name: val_var - typ: p.table.find_type_idx('MethodParam') + typ: p.table.find_type('MethodParam') pos: var_pos }) kind = .params @@ -374,14 +374,14 @@ fn (mut p Parser) comptime_for() ast.ComptimeFor { 'methods' { p.scope.register(ast.Var{ name: val_var - typ: p.table.find_type_idx('FunctionData') + typ: p.table.find_type('FunctionData') pos: var_pos }) } 'values' { p.scope.register(ast.Var{ name: val_var - typ: p.table.find_type_idx('EnumData') + typ: p.table.find_type('EnumData') pos: var_pos }) kind = .values @@ -389,7 +389,7 @@ fn (mut p Parser) comptime_for() ast.ComptimeFor { 'fields' { p.scope.register(ast.Var{ name: val_var - typ: p.table.find_type_idx('FieldData') + typ: p.table.find_type('FieldData') pos: var_pos }) kind = .fields @@ -397,7 +397,7 @@ fn (mut p Parser) comptime_for() ast.ComptimeFor { 'variants' { p.scope.register(ast.Var{ name: val_var - typ: p.table.find_type_idx('VariantData') + typ: p.table.find_type('VariantData') pos: var_pos }) kind = .variants @@ -405,7 +405,7 @@ fn (mut p Parser) comptime_for() ast.ComptimeFor { 'attributes' { p.scope.register(ast.Var{ name: val_var - typ: p.table.find_type_idx('VAttribute') + typ: p.table.find_type('VAttribute') pos: var_pos }) kind = .attributes diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 0b29ffd40..67a228cc6 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -2593,7 +2593,7 @@ fn (mut p Parser) alias_array_type() ast.Type { if idx == 0 { return ast.void_type } - sym := p.table.sym(idx) + sym := p.table.sym(ast.idx_to_type(idx)) if sym.info is ast.Alias { if sym.info.parent_type == 0 { return ast.void_type diff --git a/vlib/v/transformer/transformer.v b/vlib/v/transformer/transformer.v index 28dfa12ae..6f6c54204 100644 --- a/vlib/v/transformer/transformer.v +++ b/vlib/v/transformer/transformer.v @@ -40,7 +40,7 @@ pub fn new_transformer_with_table(table &ast.Table, pref_ &pref.Preferences) &Tr } pub fn (mut t Transformer) transform_files(ast_files []&ast.File) { - t.strings_builder_type = t.table.find_type_idx('strings.Builder') + t.strings_builder_type = t.table.find_type('strings.Builder') for i in 0 .. ast_files.len { mut file := unsafe { ast_files[i] } t.transform(mut file) -- 2.39.5