fix: composite literal child types for call expressions

This commit is contained in:
Nicholas Wiersma
2020-06-03 09:44:03 +02:00
committed by GitHub
parent d5217f7db4
commit 151a856bf2
3 changed files with 32 additions and 0 deletions

14
_test/composite10.go Normal file
View File

@@ -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[]

14
_test/composite9.go Normal file
View File

@@ -0,0 +1,14 @@
package main
import "fmt"
func main() {
a := [][]int{make([]int,0)}
for _, b := range a {
fmt.Println(b)
}
}
// Output:
// []

View File

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