cgen: fix codegen for option value on map_set (fix #23650) (#23652)

This commit is contained in:
Felipe Pena 2025-02-04 10:23:15 -03:00 committed by GitHub
parent 627cb37cca
commit eecaa64e9d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View file

@ -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() {

View file

@ -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)))}"
}