Skip to content

Commit f5e03de

Browse files
authored
checker: fix chan element type validation with inexistent type (fix #23978) (#24008)
1 parent d629a01 commit f5e03de

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

vlib/v/ast/table.v

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,9 +1499,13 @@ pub fn (t &Table) known_type_names() []string {
14991499
for _, idx in t.type_idxs {
15001500
typ := idx_to_type(idx)
15011501
// Skip `int_literal_type_idx` and `float_literal_type_idx` because they shouldn't be visible to the User.
1502-
if idx !in [0, int_literal_type_idx, float_literal_type_idx] && t.known_type_idx(typ)
1503-
&& t.sym(typ).kind != .function {
1504-
res << t.type_to_str(typ)
1502+
if idx !in [0, int_literal_type_idx, float_literal_type_idx] && t.known_type_idx(typ) {
1503+
tsym := t.sym(typ)
1504+
if tsym.kind !in [.function, .chan] {
1505+
res << t.type_to_str(typ)
1506+
} else if tsym.info is Chan && t.sym(tsym.info.elem_type).kind != .placeholder {
1507+
res << t.type_to_str(tsym.info.elem_type)
1508+
}
15051509
}
15061510
}
15071511
return res

vlib/v/checker/checker.v

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5487,6 +5487,16 @@ fn (mut c Checker) ensure_type_exists(typ ast.Type, pos token.Pos) bool {
54875487
}
54885488
}
54895489
}
5490+
.chan {
5491+
if sym.info is ast.Chan {
5492+
if !c.ensure_type_exists((sym.info as ast.Chan).elem_type, token.Pos{
5493+
...pos
5494+
col: pos.col + 5
5495+
}) {
5496+
return false
5497+
}
5498+
}
5499+
}
54905500
else {}
54915501
}
54925502
return true
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
vlib/v/checker/tests/chan_unknown_err.vv:7:11: error: unknown type `DoesNotExist`.
2+
Did you mean `DoesNotExists`?
3+
5 | struct ChanBug {
4+
6 | pub mut:
5+
7 | bug chan DoesNotExist
6+
| ~~~~~~~~~~~~
7+
8 | }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module main
2+
3+
struct DoesNotExists {}
4+
5+
struct ChanBug {
6+
pub mut:
7+
bug chan DoesNotExist
8+
}

0 commit comments

Comments
 (0)