Skip to content

Commit dfd9673

Browse files
authored
checker: add passes for top level decls (fix #26306) (#26589)
1 parent 1b6832b commit dfd9673

3 files changed

Lines changed: 52 additions & 7 deletions

File tree

‎vlib/v/checker/checker.v‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,37 @@ pub fn (mut c Checker) check(mut ast_file ast.File) {
309309

310310
c.stmt_level = 0
311311
for mut stmt in ast_file.stmts {
312-
if stmt !in [ast.ConstDecl, ast.GlobalDecl, ast.ExprStmt] {
312+
if stmt is ast.StructDecl || stmt is ast.InterfaceDecl || stmt is ast.EnumDecl
313+
|| stmt is ast.TypeDecl {
314+
c.expr_level = 0
315+
c.stmt(mut stmt)
316+
}
317+
if c.should_abort {
318+
return
319+
}
320+
}
321+
322+
c.stmt_level = 0
323+
for mut stmt in ast_file.stmts {
324+
if mut stmt is ast.FnDecl {
325+
return_sym := c.table.sym(stmt.return_type)
326+
if return_sym.info is ast.ArrayFixed
327+
&& c.array_fixed_has_unresolved_size(return_sym.info) {
328+
unsafe {
329+
c.unresolved_fixed_sizes << &stmt
330+
}
331+
}
332+
}
333+
}
334+
335+
if c.unresolved_fixed_sizes.len > 0 {
336+
c.update_unresolved_fixed_sizes()
337+
}
338+
339+
c.stmt_level = 0
340+
for mut stmt in ast_file.stmts {
341+
if stmt !in [ast.ConstDecl, ast.GlobalDecl, ast.ExprStmt] && stmt !is ast.StructDecl
342+
&& stmt !is ast.InterfaceDecl && stmt !is ast.EnumDecl && stmt !is ast.TypeDecl {
313343
c.expr_level = 0
314344
c.stmt(mut stmt)
315345
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
vlib/v/checker/tests/import_sym_builtin_override_err.vv:1:15: error: cannot import or override builtin type
2-
1 | import rand { f64 }
3-
| ~~~
4-
2 |
5-
3 | type Dot = [3]f64
61
vlib/v/checker/tests/import_sym_builtin_override_err.vv:3:12: error: unknown type `rand.f64`.
72
Did you mean `rand.PRNG`?
83
1 | import rand { f64 }
9-
2 |
4+
2 |
105
3 | type Dot = [3]f64
116
| ~~~~~~
7+
vlib/v/checker/tests/import_sym_builtin_override_err.vv:1:15: error: cannot import or override builtin type
8+
1 | import rand { f64 }
9+
| ~~~
10+
2 |
11+
3 | type Dot = [3]f64
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
fn get_chunkmap_at_coords(mapp []Chunk) [chunk_size][chunk_size]u64 {
2+
return mapp[0].id_map
3+
}
4+
5+
const chunk_size = 100
6+
7+
struct Chunk {
8+
id_map [chunk_size][chunk_size]u64
9+
}
10+
11+
fn main() {
12+
x := get_chunkmap_at_coords([]Chunk{len: 1})
13+
assert x.len == 100
14+
assert x[0].len == 100
15+
}

0 commit comments

Comments
 (0)