Skip to content

Commit 947771f

Browse files
committed
Fix type checker for range operator
1 parent d06fea9 commit 947771f

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

checker/checker.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func (v *visitor) BinaryNode(node *ast.BinaryNode) reflect.Type {
253253

254254
case "..":
255255
if isInteger(l) && isInteger(r) {
256-
return arrayType
256+
return reflect.SliceOf(integerType)
257257
}
258258

259259
default:
@@ -501,8 +501,7 @@ func (v *visitor) BuiltinNode(node *ast.BuiltinNode) reflect.Type {
501501
closure.NumOut() == 1 &&
502502
closure.NumIn() == 1 && isInterface(closure.In(0)) {
503503

504-
return reflect.ArrayOf(0, closure.Out(0))
505-
504+
return reflect.SliceOf(closure.Out(0))
506505
}
507506
panic(v.error(node.Arguments[1], "closure should has one input and one output param"))
508507

checker/checker_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ func TestCheck(t *testing.T) {
158158
"Variadic('', 1, 2) + Variadic('')",
159159
"Foo.Variadic('', 1, 2) + Foo.Variadic('')",
160160
"count(1..30, {# % 3 == 0}) > 0",
161+
"map(1..3, {#}) == [1,2,3]",
161162
}
162163
for _, test := range typeTests {
163164
var err error

0 commit comments

Comments
 (0)