@@ -4093,7 +4093,7 @@ fn (mut g Gen) ident(node ast.Ident) {
4093
4093
if node.obj is ast.Var {
4094
4094
if ! g.is_assign_lhs && node.obj.is_comptime_field {
4095
4095
if g.comptime_for_field_type.has_flag (.option) {
4096
- if (g.inside_opt_or_res && node.or_expr.kind == .absent) || g.left_is_opt {
4096
+ if (g.inside_opt_or_res || g.left_is_opt) && node.or_expr.kind == .absent {
4097
4097
g.write ('${name} ' )
4098
4098
} else {
4099
4099
g.write ('/*opt*/' )
@@ -4103,7 +4103,8 @@ fn (mut g Gen) ident(node ast.Ident) {
4103
4103
} else {
4104
4104
g.write ('${name} ' )
4105
4105
}
4106
- if node.or_expr.kind != .absent {
4106
+ if node.or_expr.kind != .absent && ! (g.inside_opt_or_res && g.inside_assign
4107
+ && ! g.is_assign_lhs) {
4107
4108
stmt_str := g.go_before_stmt (0 ).trim_space ()
4108
4109
g.empty_line = true
4109
4110
g.or_block (name, node.or_expr, g.comptime_for_field_type)
@@ -4117,14 +4118,15 @@ fn (mut g Gen) ident(node ast.Ident) {
4117
4118
// `x = new_opt()` => `x = new_opt()` (g.right_is_opt == true)
4118
4119
// `println(x)` => `println(*(int*)x.data)`
4119
4120
if node.info.is_option && ! (g.is_assign_lhs && g.right_is_opt) {
4120
- if (g.inside_opt_or_res && node.or_expr.kind == .absent) || g.left_is_opt {
4121
+ if (g.inside_opt_or_res || g.left_is_opt) && node.or_expr.kind == .absent {
4121
4122
g.write ('${name} ' )
4122
4123
} else {
4123
4124
g.write ('/*opt*/' )
4124
4125
styp := g.base_type (node.info.typ)
4125
4126
g.write ('(*(${styp} *)${name} .data)' )
4126
4127
}
4127
- if node.or_expr.kind != .absent && ! (g.inside_assign && ! g.is_assign_lhs) {
4128
+ if node.or_expr.kind != .absent && ! (g.inside_opt_or_res && g.inside_assign
4129
+ && ! g.is_assign_lhs) {
4128
4130
stmt_str := g.go_before_stmt (0 ).trim_space ()
4129
4131
g.empty_line = true
4130
4132
g.or_block (name, node.or_expr, node.info.typ)
0 commit comments