checker: fix checking uninitialized refs
parent
b09fd66aa2
commit
71c2b26103
|
@ -330,7 +330,7 @@ pub fn (mut c Checker) struct_init(struct_init mut ast.StructInit) table.Type {
|
||||||
}
|
}
|
||||||
// Check uninitialized refs
|
// Check uninitialized refs
|
||||||
for field in info.fields {
|
for field in info.fields {
|
||||||
if field.name in inited_fields {
|
if field.has_default_expr || field.name in inited_fields {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if field.typ.is_ptr() {
|
if field.typ.is_ptr() {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
vlib/v/checker/tests/reference_field_must_be_initialized.v:8:7: error: reference field `Node.next` must be initialized
|
vlib/v/checker/tests/reference_field_must_be_initialized.v:8:7: error: reference field `Node.next` must be initialized
|
||||||
6 |
|
6 |
|
||||||
7 | fn main(){
|
7 | fn main(){
|
||||||
8 | n := Node{ data: 123 }
|
8 | n := Node{ data: 123 }
|
||||||
| ~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~~
|
||||||
9 | eprintln('n.data: $n.data')
|
9 | eprintln('n.data: $n.data')
|
||||||
10 | }
|
10 | }
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
module main
|
module main
|
||||||
struct Node {
|
struct Node {
|
||||||
data int
|
data int
|
||||||
next &Node = 0
|
next &Node
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main(){
|
fn main(){
|
||||||
n := Node{ data: 123 }
|
n := Node{ data: 123 }
|
||||||
eprintln('n.data: $n.data')
|
eprintln('n.data: $n.data')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue