Skip to content

Commit eecaa64

Browse files
authored
cgen: fix codegen for option value on map_set (fix #23650) (#23652)
1 parent 627cb37 commit eecaa64

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

vlib/v/gen/c/assign.v

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn (mut g Gen) expr_with_opt(expr ast.Expr, expr_typ ast.Type, ret_typ ast.Type)
138138
defer {
139139
g.inside_opt_or_res = old_inside_opt_or_res
140140
}
141-
if expr_typ.has_flag(.option) && ret_typ.has_flag(.option)
141+
if expr_typ.has_flag(.option) && ret_typ.has_flag(.option) && !g.is_arraymap_set
142142
&& expr in [ast.SelectorExpr, ast.DumpExpr, ast.Ident, ast.ComptimeSelector, ast.AsCast, ast.CallExpr, ast.MatchExpr, ast.IfExpr, ast.IndexExpr, ast.UnsafeExpr, ast.CastExpr] {
143143
if expr in [ast.Ident, ast.CastExpr] {
144144
if expr_typ.idx() != ret_typ.idx() {
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
type Any = ?int | ?string
2+
3+
struct TestConfig {
4+
timeout ?int
5+
}
6+
7+
fn test_main() {
8+
mut r := TestConfig{}
9+
mut m := map[string]?Any{}
10+
m['timeout'] = r.timeout
11+
assert m.str() == "{'timeout': Option(Any(Option(none)))}"
12+
}

0 commit comments

Comments
 (0)