From dfd9673611a5646e1e7ea4935616237fde6b8c88 Mon Sep 17 00:00:00 2001 From: CreeperFace <165158232+dy-tea@users.noreply.github.com> Date: Sat, 14 Feb 2026 02:05:43 +0000 Subject: [PATCH] checker: add passes for top level decls (fix #26306) (#26589) --- vlib/v/checker/checker.v | 32 ++++++++++++++++++- .../tests/import_sym_builtin_override_err.out | 12 +++---- ...d_array_return_unresolved_test_reordered.v | 15 +++++++++ 3 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 vlib/v/tests/consts/const_fixed_array_return_unresolved_test_reordered.v diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 52bfcf689..4ff9db583 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -309,7 +309,37 @@ pub fn (mut c Checker) check(mut ast_file ast.File) { c.stmt_level = 0 for mut stmt in ast_file.stmts { - if stmt !in [ast.ConstDecl, ast.GlobalDecl, ast.ExprStmt] { + if stmt is ast.StructDecl || stmt is ast.InterfaceDecl || stmt is ast.EnumDecl + || stmt is ast.TypeDecl { + c.expr_level = 0 + c.stmt(mut stmt) + } + if c.should_abort { + return + } + } + + c.stmt_level = 0 + for mut stmt in ast_file.stmts { + if mut stmt is ast.FnDecl { + return_sym := c.table.sym(stmt.return_type) + if return_sym.info is ast.ArrayFixed + && c.array_fixed_has_unresolved_size(return_sym.info) { + unsafe { + c.unresolved_fixed_sizes << &stmt + } + } + } + } + + if c.unresolved_fixed_sizes.len > 0 { + c.update_unresolved_fixed_sizes() + } + + c.stmt_level = 0 + for mut stmt in ast_file.stmts { + if stmt !in [ast.ConstDecl, ast.GlobalDecl, ast.ExprStmt] && stmt !is ast.StructDecl + && stmt !is ast.InterfaceDecl && stmt !is ast.EnumDecl && stmt !is ast.TypeDecl { c.expr_level = 0 c.stmt(mut stmt) } diff --git a/vlib/v/checker/tests/import_sym_builtin_override_err.out b/vlib/v/checker/tests/import_sym_builtin_override_err.out index 18bb0e90a..cba84b413 100644 --- a/vlib/v/checker/tests/import_sym_builtin_override_err.out +++ b/vlib/v/checker/tests/import_sym_builtin_override_err.out @@ -1,11 +1,11 @@ -vlib/v/checker/tests/import_sym_builtin_override_err.vv:1:15: error: cannot import or override builtin type - 1 | import rand { f64 } - | ~~~ - 2 | - 3 | type Dot = [3]f64 vlib/v/checker/tests/import_sym_builtin_override_err.vv:3:12: error: unknown type `rand.f64`. Did you mean `rand.PRNG`? 1 | import rand { f64 } - 2 | + 2 | 3 | type Dot = [3]f64 | ~~~~~~ +vlib/v/checker/tests/import_sym_builtin_override_err.vv:1:15: error: cannot import or override builtin type + 1 | import rand { f64 } + | ~~~ + 2 | + 3 | type Dot = [3]f64 \ No newline at end of file diff --git a/vlib/v/tests/consts/const_fixed_array_return_unresolved_test_reordered.v b/vlib/v/tests/consts/const_fixed_array_return_unresolved_test_reordered.v new file mode 100644 index 000000000..7550e5e3f --- /dev/null +++ b/vlib/v/tests/consts/const_fixed_array_return_unresolved_test_reordered.v @@ -0,0 +1,15 @@ +fn get_chunkmap_at_coords(mapp []Chunk) [chunk_size][chunk_size]u64 { + return mapp[0].id_map +} + +const chunk_size = 100 + +struct Chunk { + id_map [chunk_size][chunk_size]u64 +} + +fn main() { + x := get_chunkmap_at_coords([]Chunk{len: 1}) + assert x.len == 100 + assert x[0].len == 100 +} -- 2.39.5