@@ -4245,7 +4245,20 @@ fn (mut g Gen) ident(node ast.Ident) {
4245
4245
if is_auto_heap {
4246
4246
g.write ('(*(${styp} *)${name} ->data)' )
4247
4247
} else {
4248
- g.write ('(*(${styp} *)${name} .data)' )
4248
+ type_sym := g.table.sym (node.info.typ)
4249
+ if type_sym.kind == .alias {
4250
+ // Alias to Option type
4251
+ parent_typ := (type_sym.info as ast.Alias ).parent_type
4252
+ if parent_typ.has_flag (.option) {
4253
+ g.write ('*((${g.base_type(parent_typ)} *)' )
4254
+ }
4255
+ g.write ('(*(${styp} *)${name} .data)' )
4256
+ if parent_typ.has_flag (.option) {
4257
+ g.write ('.data)' )
4258
+ }
4259
+ } else {
4260
+ g.write ('(*(${styp} *)${name} .data)' )
4261
+ }
4249
4262
}
4250
4263
}
4251
4264
if node.or_expr.kind != .absent && ! (g.inside_opt_or_res && g.inside_assign
@@ -4398,17 +4411,38 @@ fn (mut g Gen) cast_expr(node ast.CastExpr) {
4398
4411
mut cast_label := ''
4399
4412
// `ast.string_type` is done for MSVC's bug
4400
4413
if sym.kind != .alias
4401
- || (sym.info as ast.Alias ).parent_type ! in [expr_type, ast.string_type] {
4414
+ || (! (sym.info as ast.Alias ).parent_type.has_flag (.option)
4415
+ && (sym.info as ast.Alias ).parent_type ! in [expr_type, ast.string_type]) {
4402
4416
cast_label = '(${styp} )'
4403
4417
}
4404
4418
if node.typ.has_flag (.option) && node.expr is ast.None {
4405
4419
g.gen_option_error (node.typ, node.expr)
4406
4420
} else if node.typ.has_flag (.option) {
4407
- if sym.kind == .alias && node.expr_type.has_flag (.option) {
4408
- g.expr_opt_with_cast (node.expr, expr_type, node.typ)
4421
+ if sym.kind == .alias {
4422
+ if (sym.info as ast.Alias ).parent_type.has_flag (.option) {
4423
+ cur_stmt := g.go_before_stmt (0 )
4424
+ g.empty_line = true
4425
+ parent_type := (sym.info as ast.Alias ).parent_type
4426
+ tmp_var := g.new_tmp_var ()
4427
+ tmp_var2 := g.new_tmp_var ()
4428
+ g.writeln ('${styp} ${tmp_var} ;' )
4429
+ g.writeln ('${g.typ(parent_type)} ${tmp_var2} ;' )
4430
+ g.write ('_option_ok(&(${g.base_type(parent_type)} []) { ' )
4431
+ g.expr (node.expr)
4432
+ g.writeln (' }, (${c.option_name} *)(&${tmp_var2} ), sizeof(${g.base_type(parent_type)} ));' )
4433
+ g.writeln ('_option_ok(&(${g.typ(parent_type)} []) { ${tmp_var2} }, (${c.option_name} *)&${tmp_var} , sizeof(${g.typ(parent_type)} ));' )
4434
+ g.write (cur_stmt)
4435
+ g.write (tmp_var)
4436
+ } else if node.expr_type.has_flag (.option) {
4437
+ g.expr_opt_with_cast (node.expr, expr_type, node.typ)
4438
+ } else {
4439
+ g.expr_with_opt (node.expr, expr_type, node.typ)
4440
+ }
4409
4441
} else {
4410
4442
g.expr_with_opt (node.expr, expr_type, node.typ)
4411
4443
}
4444
+ } else if sym.kind == .alias && (sym.info as ast.Alias ).parent_type.has_flag (.option) {
4445
+ g.expr_with_opt (node.expr, expr_type, (sym.info as ast.Alias ).parent_type)
4412
4446
} else {
4413
4447
g.write ('(${cast_label} (' )
4414
4448
if sym.kind == .alias && g.table.final_sym (node.typ).kind == .string {
0 commit comments