From 151a856bf2f044f5e412646e3a9a22d69773b9d7 Mon Sep 17 00:00:00 2001 From: Nicholas Wiersma Date: Wed, 3 Jun 2020 09:44:03 +0200 Subject: [PATCH] fix: composite literal child types for call expressions --- _test/composite10.go | 14 ++++++++++++++ _test/composite9.go | 14 ++++++++++++++ interp/cfg.go | 4 ++++ 3 files changed, 32 insertions(+) create mode 100644 _test/composite10.go create mode 100644 _test/composite9.go diff --git a/_test/composite10.go b/_test/composite10.go new file mode 100644 index 00000000..9b52706a --- /dev/null +++ b/_test/composite10.go @@ -0,0 +1,14 @@ +package main + +import "fmt" + +func main() { + a := []map[int]int{make(map[int]int)} + + for _, b := range a { + fmt.Println(b) + } +} + +// Output: +// map[] diff --git a/_test/composite9.go b/_test/composite9.go new file mode 100644 index 00000000..83efa882 --- /dev/null +++ b/_test/composite9.go @@ -0,0 +1,14 @@ +package main + +import "fmt" + +func main() { + a := [][]int{make([]int,0)} + + for _, b := range a { + fmt.Println(b) + } +} + +// Output: +// [] diff --git a/interp/cfg.go b/interp/cfg.go index 7b863132..b792dfac 100644 --- a/interp/cfg.go +++ b/interp/cfg.go @@ -248,6 +248,10 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) { case binaryExpr, unaryExpr: // Do not attempt to propagate composite type to operator expressions, // it breaks constant folding. + case callExpr: + if c.typ, err = nodeType(interp, sc, c); err != nil { + return false + } default: c.typ = n.typ }