File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4013,6 +4013,9 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) {
40134013 if i == 0 && (is_option_unwrap || nested_unwrap) {
40144014 deref := if g.inside_selector {
40154015 '*' .repeat (field.smartcasts.last ().nr_muls () + 1 )
4016+ } else if sym.kind == .interface && ! typ.is_ptr ()
4017+ && field.orig_type.has_flag (.option) {
4018+ ''
40164019 } else {
40174020 '*'
40184021 }
@@ -4196,7 +4199,7 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) {
41964199 }
41974200 g.write (field_name)
41984201 if is_option_unwrap {
4199- if field_typ. is_ptr () && g.table.final_sym (node.expr_type).kind in [.sum_type, .interface ] {
4202+ if g.table.final_sym (node.expr_type).kind in [.sum_type, .interface ] {
42004203 g.write ('->' )
42014204 } else {
42024205 g.write ('.' )
Original file line number Diff line number Diff line change 1+ interface IBar {
2+ opt ? string
3+ }
4+
5+ struct Bar implements IBar {
6+ opt ? string
7+ }
8+
9+ struct Foo {
10+ field IBar
11+ }
12+
13+ fn (f &Foo) t () {
14+ if f.field.opt != none {
15+ assert f.field.opt == 'foo'
16+ }
17+ }
18+
19+ fn test_main () {
20+ a := Foo{
21+ field: Bar{
22+ opt: 'foo'
23+ }
24+ }
25+ if a.field.opt != none {
26+ assert a.field.opt == 'foo'
27+ }
28+ a.t ()
29+ }
You can’t perform that action at this time.
0 commit comments