mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: disallow none type in struct fields (#16425)
This commit is contained in:
parent
91ecfb917c
commit
58cee6ccc8
@ -84,6 +84,10 @@ pub fn (mut c Checker) struct_decl(mut node ast.StructDecl) {
|
||||
c.error('cannot use multi return as field type', field.type_pos)
|
||||
}
|
||||
|
||||
if sym.kind == .none_ {
|
||||
c.error('cannot use `none` as field type', field.type_pos)
|
||||
}
|
||||
|
||||
if field.has_default_expr {
|
||||
c.expected_type = field.typ
|
||||
default_expr_type := c.expr(field.default_expr)
|
||||
|
6
vlib/v/checker/tests/struct_none_field_type_err.out
Normal file
6
vlib/v/checker/tests/struct_none_field_type_err.out
Normal file
@ -0,0 +1,6 @@
|
||||
vlib/v/checker/tests/struct_none_field_type_err.vv:2:7: error: cannot use `none` as field type
|
||||
1 | struct Jaca {
|
||||
2 | lala none
|
||||
| ~~~~
|
||||
3 | }
|
||||
4 |
|
12
vlib/v/checker/tests/struct_none_field_type_err.vv
Normal file
12
vlib/v/checker/tests/struct_none_field_type_err.vv
Normal file
@ -0,0 +1,12 @@
|
||||
struct Jaca {
|
||||
lala none
|
||||
}
|
||||
|
||||
fn f() {
|
||||
mut s := Jaca{
|
||||
lala: none
|
||||
}
|
||||
println(s)
|
||||
}
|
||||
|
||||
f()
|
Loading…
Reference in New Issue
Block a user