Skip to content

Commit

Permalink
Fix type check for fast call path
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Mar 26, 2020
1 parent aa52e70 commit 5ff1280
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ func (v *visitor) FunctionNode(node *ast.FunctionNode) reflect.Type {
if !isInterface(fn) &&
fn.IsVariadic() &&
fn.NumIn() == inputParamsCount &&
fn.NumOut() == 1 {
fn.NumOut() == 1 &&
fn.Out(0).Kind() == reflect.Interface {
rest := fn.In(fn.NumIn() - 1) // function has only one param for functions and two for methods
if rest.Kind() == reflect.Slice && rest.Elem().Kind() == reflect.Interface {
node.Fast = true
Expand Down
12 changes: 12 additions & 0 deletions expr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,10 @@ func TestExpr(t *testing.T) {
`map(filter(Tweets, {len(.Text) > 10}), {Format(.Date)})`,
[]interface{}{"23 Oct 17 18:30 UTC", "23 Oct 17 18:30 UTC"},
},
{
`Concat("a", 1, [])`,
`a1[]`,
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -1140,6 +1144,14 @@ func (*mockEnv) Variadic(x string, xs ...int) []int {
return xs
}

func (*mockEnv) Concat(list ...interface{}) string {
out := ""
for _, e := range list {
out += fmt.Sprintf("%v", e)
}
return out
}

func (*mockEnv) Float(i interface{}) float64 {
switch t := i.(type) {
case int:
Expand Down

0 comments on commit 5ff1280

Please sign in to comment.