mirror of
https://github.com/vlang/v.git
synced 2025-09-13 17:36:52 -04:00
checker: fix field ?&Type
without default value (#19786)
This commit is contained in:
parent
6fa9a84753
commit
09f3e1e971
@ -727,14 +727,16 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
|
|||||||
node.pos)
|
node.pos)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if sym.kind == .struct_ {
|
if !field.typ.has_flag(.option) {
|
||||||
c.check_ref_fields_initialized(sym, mut checked_types, '${type_sym.name}.${field.name}',
|
if sym.kind == .struct_ {
|
||||||
node)
|
c.check_ref_fields_initialized(sym, mut checked_types, '${type_sym.name}.${field.name}',
|
||||||
} else if sym.kind == .alias {
|
node)
|
||||||
parent_sym := c.table.sym((sym.info as ast.Alias).parent_type)
|
} else if sym.kind == .alias {
|
||||||
if parent_sym.kind == .struct_ {
|
parent_sym := c.table.sym((sym.info as ast.Alias).parent_type)
|
||||||
c.check_ref_fields_initialized(parent_sym, mut checked_types,
|
if parent_sym.kind == .struct_ {
|
||||||
'${type_sym.name}.${field.name}', node)
|
c.check_ref_fields_initialized(parent_sym, mut checked_types,
|
||||||
|
'${type_sym.name}.${field.name}', node)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Do not allow empty uninitialized interfaces
|
// Do not allow empty uninitialized interfaces
|
||||||
|
21
vlib/v/checker/tests/option_ref_init_err.out
Normal file
21
vlib/v/checker/tests/option_ref_init_err.out
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
vlib/v/checker/tests/option_ref_init_err.vv:9:18: warning: unnecessary default value of `none`: struct fields are zeroed by default
|
||||||
|
7 | mut:
|
||||||
|
8 | a0 ?&Viewport
|
||||||
|
9 | a1 ?&Viewport = none
|
||||||
|
| ~~~~
|
||||||
|
10 | a2 ?&Viewport = none
|
||||||
|
11 | a3 ?&Viewport = unsafe { nil }
|
||||||
|
vlib/v/checker/tests/option_ref_init_err.vv:10:18: warning: unnecessary default value of `none`: struct fields are zeroed by default
|
||||||
|
8 | a0 ?&Viewport
|
||||||
|
9 | a1 ?&Viewport = none
|
||||||
|
10 | a2 ?&Viewport = none
|
||||||
|
| ~~~~
|
||||||
|
11 | a3 ?&Viewport = unsafe { nil }
|
||||||
|
12 | a4 ?&Viewport = nil
|
||||||
|
vlib/v/checker/tests/option_ref_init_err.vv:12:18: error: `nil` is only allowed in `unsafe` code
|
||||||
|
10 | a2 ?&Viewport = none
|
||||||
|
11 | a3 ?&Viewport = unsafe { nil }
|
||||||
|
12 | a4 ?&Viewport = nil
|
||||||
|
| ~~~
|
||||||
|
13 | }
|
||||||
|
14 |
|
17
vlib/v/checker/tests/option_ref_init_err.vv
Normal file
17
vlib/v/checker/tests/option_ref_init_err.vv
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
struct Viewport {
|
||||||
|
mut:
|
||||||
|
parent &Window
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Window {
|
||||||
|
mut:
|
||||||
|
a0 ?&Viewport
|
||||||
|
a1 ?&Viewport = none
|
||||||
|
a2 ?&Viewport = none
|
||||||
|
a3 ?&Viewport = unsafe { nil }
|
||||||
|
a4 ?&Viewport = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
_ := &Window{}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user