Skip to content

Commit

Permalink
cgen: fix codegen for option value on map_set (fix #23650) (#23652)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Feb 4, 2025
1 parent 627cb37 commit eecaa64
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/v/gen/c/assign.v
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn (mut g Gen) expr_with_opt(expr ast.Expr, expr_typ ast.Type, ret_typ ast.Type)
defer {
g.inside_opt_or_res = old_inside_opt_or_res
}
if expr_typ.has_flag(.option) && ret_typ.has_flag(.option)
if expr_typ.has_flag(.option) && ret_typ.has_flag(.option) && !g.is_arraymap_set
&& expr in [ast.SelectorExpr, ast.DumpExpr, ast.Ident, ast.ComptimeSelector, ast.AsCast, ast.CallExpr, ast.MatchExpr, ast.IfExpr, ast.IndexExpr, ast.UnsafeExpr, ast.CastExpr] {
if expr in [ast.Ident, ast.CastExpr] {
if expr_typ.idx() != ret_typ.idx() {
Expand Down
12 changes: 12 additions & 0 deletions vlib/v/tests/options/option_map_set_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type Any = ?int | ?string

struct TestConfig {
timeout ?int
}

fn test_main() {
mut r := TestConfig{}
mut m := map[string]?Any{}
m['timeout'] = r.timeout
assert m.str() == "{'timeout': Option(Any(Option(none)))}"
}

0 comments on commit eecaa64

Please sign in to comment.