@@ -3995,21 +3995,27 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) {
3995
3995
// check first if field is sum type because scope searching is expensive
3996
3996
scope := g.file.scope.innermost (node.pos.pos)
3997
3997
if field := scope.find_struct_field (node.expr.str (), node.expr_type, node.field_name) {
3998
+ nested_unwrap := is_option && field.smartcasts.len > 1
3998
3999
is_option_unwrap = is_option && field.smartcasts.len > 0
3999
4000
&& field.typ.clear_flag (.option) == field.smartcasts.last ()
4000
4001
if field.orig_type.is_ptr () {
4001
4002
sum_type_dot = '->'
4002
4003
}
4004
+ if nested_unwrap && field_sym.kind == .sum_type {
4005
+ g.write ('*(' )
4006
+ }
4003
4007
for i, typ in field.smartcasts {
4004
- if i == 0 && is_option_unwrap {
4008
+ if i == 0 && ( is_option_unwrap || nested_unwrap) {
4005
4009
deref := if g.inside_selector {
4006
4010
'*' .repeat (field.smartcasts.last ().nr_muls () + 1 )
4007
4011
} else {
4008
4012
'*'
4009
4013
}
4010
4014
g.write ('(${deref} (${g.styp(typ)} *)' )
4011
4015
}
4012
- g.write ('(' )
4016
+ if i == 0 || ! nested_unwrap {
4017
+ g.write ('(' )
4018
+ }
4013
4019
if field_sym.kind == .sum_type && ! is_option {
4014
4020
g.write ('*' )
4015
4021
}
@@ -4029,7 +4035,11 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) {
4029
4035
agg_sym := g.table.sym (cast_sym.info.types[g.aggregate_type_idx])
4030
4036
sum_type_deref_field + = '_${agg_sym.cname} '
4031
4037
} else {
4032
- sum_type_deref_field + = '_${cast_sym.cname} '
4038
+ if i == 0 && nested_unwrap {
4039
+ sum_type_deref_field + = 'data)'
4040
+ } else {
4041
+ sum_type_deref_field + = '_${cast_sym.cname} '
4042
+ }
4033
4043
}
4034
4044
}
4035
4045
}
0 commit comments