diff --git a/pkg/compiler/for_test.go b/pkg/compiler/for_test.go index df2fa06df..f2995cc3c 100644 --- a/pkg/compiler/for_test.go +++ b/pkg/compiler/for_test.go @@ -737,6 +737,20 @@ func TestForLoopRangeMap(t *testing.T) { eval(t, src, big.NewInt(42)) } +func TestForLoopRangeTypeConversion(t *testing.T) { + src := `package foo + type intArr []int + func Main() int { + a := []int{1, 2, 3} + s := 0 + for _, v := range intArr(a) { + s += v + } + return s + }` + eval(t, src, big.NewInt(6)) +} + func TestForLoopComplexConditions(t *testing.T) { src := ` package foo diff --git a/pkg/compiler/func_scope.go b/pkg/compiler/func_scope.go index 384e14992..133a30d9d 100644 --- a/pkg/compiler/func_scope.go +++ b/pkg/compiler/func_scope.go @@ -102,6 +102,11 @@ func (c *funcScope) analyzeVoidCalls(node ast.Node) bool { } case *ast.BinaryExpr: return false + case *ast.RangeStmt: + ce, ok := n.X.(*ast.CallExpr) + if ok { + c.voidCalls[ce] = false + } case *ast.IfStmt: // we can't just return `false`, because we still need to process body ce, ok := n.Cond.(*ast.CallExpr)