1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: check struct field with default expression (#15151)

This commit is contained in:
yuyi 2022-07-21 15:33:34 +08:00 committed by GitHub
parent 49228e1acd
commit 7029e39088
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View File

@ -320,7 +320,7 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type {
}
if type_sym.name.len == 1 && !isnil(c.table.cur_fn) && c.table.cur_fn.generic_names.len == 0 {
c.error('unknown struct `$type_sym.name`', node.pos)
return 0
return ast.void_type
}
match type_sym.kind {
.placeholder {

View File

@ -0,0 +1,6 @@
vlib/v/checker/tests/struct_field_with_default_err.vv:2:22: error: unknown struct `T`
1 | struct Dummy<T> {
2 | arbitrary_field T = T{}
| ~~~
3 | }
4 |

View File

@ -0,0 +1,5 @@
struct Dummy<T> {
arbitrary_field T = T{}
}
fn main() {}