Skip to content

Commit 64c1034

Browse files
authored
checker: skip init check for options (fix #25798) (#25830)
1 parent 231b0d9 commit 64c1034

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

vlib/v/checker/struct.v

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,10 @@ fn (mut c Checker) check_ref_fields_initialized(struct_sym &ast.TypeSymbol, mut
11881188
// an embedded struct field
11891189
continue
11901190
}
1191+
if field.typ.has_flag(.option) {
1192+
// defaults to `none`
1193+
continue
1194+
}
11911195
checked_types << field.typ
11921196
c.check_ref_fields_initialized(sym, mut checked_types, '${linked_name}.${field.name}',
11931197
pos)
@@ -1231,6 +1235,10 @@ fn (mut c Checker) check_ref_fields_initialized_note(struct_sym &ast.TypeSymbol,
12311235
// an embedded struct field
12321236
continue
12331237
}
1238+
if field.typ.has_flag(.option) {
1239+
// defaults to `none`
1240+
continue
1241+
}
12341242
checked_types << field.typ
12351243
c.check_ref_fields_initialized(sym, mut checked_types, '${linked_name}.${field.name}',
12361244
pos)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
struct Foo {
2+
data &int
3+
}
4+
5+
struct FooHolder {
6+
foo ?&Foo
7+
}
8+
9+
struct FooMain {
10+
foo_holder FooHolder
11+
}
12+
13+
struct FooMain2 {
14+
foo_main FooMain
15+
}
16+
17+
fn test_main() {
18+
a := FooMain{}
19+
assert a.foo_holder.foo == none
20+
21+
b := FooMain2{}
22+
assert b.foo_main.foo_holder.foo == none
23+
}

0 commit comments

Comments
 (0)