Skip to content

Commit 7029e39

Browse files
authored
checker: check struct field with default expression (#15151)
1 parent 49228e1 commit 7029e39

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

vlib/v/checker/struct.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type {
320320
}
321321
if type_sym.name.len == 1 && !isnil(c.table.cur_fn) && c.table.cur_fn.generic_names.len == 0 {
322322
c.error('unknown struct `$type_sym.name`', node.pos)
323-
return 0
323+
return ast.void_type
324324
}
325325
match type_sym.kind {
326326
.placeholder {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
vlib/v/checker/tests/struct_field_with_default_err.vv:2:22: error: unknown struct `T`
2+
1 | struct Dummy<T> {
3+
2 | arbitrary_field T = T{}
4+
| ~~~
5+
3 | }
6+
4 |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
struct Dummy<T> {
2+
arbitrary_field T = T{}
3+
}
4+
5+
fn main() {}

0 commit comments

Comments
 (0)