compiler: allow to use type conversion in range
This commit is contained in:
parent
3af7ce8c6b
commit
74dda0ac66
2 changed files with 19 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue