diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 631cfdab76..0b48afca9e 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -1726,6 +1726,10 @@ fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type { c.check_or_expr(node.or_block, unwrapped_typ, c.expected_or_type, node) c.expected_or_type = ast.void_type } + if c.pref.skip_unused && node.or_block.kind != .absent + && !c.table.used_features.option_or_result { + c.table.used_features.option_or_result = true + } return field.typ } if mut method := c.table.sym(c.unwrap_generic(typ)).find_method_with_generic_parent(field_name) { diff --git a/vlib/v/tests/skip_unused/selector_option.run.out b/vlib/v/tests/skip_unused/selector_option.run.out new file mode 100644 index 0000000000..0cfbf08886 --- /dev/null +++ b/vlib/v/tests/skip_unused/selector_option.run.out @@ -0,0 +1 @@ +2 diff --git a/vlib/v/tests/skip_unused/selector_option.skip_unused.run.out b/vlib/v/tests/skip_unused/selector_option.skip_unused.run.out new file mode 100644 index 0000000000..0cfbf08886 --- /dev/null +++ b/vlib/v/tests/skip_unused/selector_option.skip_unused.run.out @@ -0,0 +1 @@ +2 diff --git a/vlib/v/tests/skip_unused/selector_option.vv b/vlib/v/tests/skip_unused/selector_option.vv new file mode 100644 index 0000000000..94a1844551 --- /dev/null +++ b/vlib/v/tests/skip_unused/selector_option.vv @@ -0,0 +1,15 @@ +module main + +struct GameObject { +mut: + id int = 1 + parent ?&GameObject +} + +fn main() { + mut gameobject := GameObject{} + gameobject.parent = &GameObject{ + id: 2 + } + println('${gameobject.parent?.id}') +}