Skip to content

Commit

Permalink
Patch decomposition of composite lits
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Sep 25, 2023
1 parent 035b04f commit 95d67bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion compiler/desugar.go
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,13 @@ func (d *desugarer) decomposeExpression(expr ast.Expr, flags exprFlags) (ast.Exp

case *ast.CompositeLit:
for i, elt := range e.Elts {
e.Elts[i] = decompose(elt)
switch kv := elt.(type) {
case *ast.KeyValueExpr:
kv.Key = decompose(kv.Key)
kv.Value = decompose(kv.Value)
default:
e.Elts[i] = decompose(elt)
}
}
// skip e.Type (type expression)

Expand Down
14 changes: 14 additions & 0 deletions compiler/desugar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,20 @@ _l0:
_v0 := e()
a, b, c = d(_v0)
}
`,
},
{
name: "key value expr",
body: "Foo{Bar: a(b()), Baz: c(d())}",
// TODO: fix order of evaluation here
expect: `
{
_v3 := d()
_v2 := b()
_v1 := c(_v3)
_v0 := a(_v2)
Foo{Bar: _v0, Baz: _v1}
}
`,
},
} {
Expand Down

0 comments on commit 95d67bf

Please sign in to comment.