Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ func (v *Checker) checkArguments(
if isVariadic && i >= fnNumIn-1 {
// For variadic arguments fn(xs ...int), go replaces type of xs (int) with ([]int).
// As we compare arguments one by one, we need underling type.
in = fn.InElem(&v.config.NtCache, fnNumIn-1)
in = fn.InElem(&v.config.NtCache, fnNumIn-1+fnInOffset)
} else {
in = fn.In(&v.config.NtCache, i+fnInOffset)
}
Expand Down
1 change: 1 addition & 0 deletions checker/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func TestCheck(t *testing.T) {
{"let foo = 1; foo == 1"},
{"(Embed).EmbedPointerEmbedInt > 0"},
{"(true ? [1] : [[1]])[0][0] == 1"},
{"Foo.VariadicMethod('a', 'b', 'c')"},
}

c := new(checker.Checker)
Expand Down
44 changes: 44 additions & 0 deletions test/issues/888/issue_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"testing"

"github.com/expr-lang/expr"
"github.com/expr-lang/expr/internal/testify/require"
)

type Container struct {
ID string
List []string
}

func (c Container) IncludesAny(s ...string) bool {
for _, l := range c.List {
// Note: original issue used "slices.Contains" but
// it is not available in the minimum Go version of expr (1.18).
for _, v := range s {
if v == l {
return true
}
}
}
return false
}

func TestIssue888(t *testing.T) {
env := map[string]any{
"Container": Container{
ID: "id",
List: []string{"foo", "bar", "baz"},
},
}

code := `Container.IncludesAny("nope", "nope again", "bar")`

program, err := expr.Compile(code, expr.Env(env))
require.NoError(t, err)

output, err := expr.Run(program, env)
require.NoError(t, err)
require.Equal(t, true, output)
}
4 changes: 4 additions & 0 deletions test/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ func (Foo) String() string {
return "Foo.String"
}

func (Foo) VariadicMethod(_ ...string) bool {
return true
}

type Bar struct {
Baz string
}
Expand Down
Loading