|
| 1 | +package issue_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/expr-lang/expr" |
| 7 | + "github.com/expr-lang/expr/internal/testify/require" |
| 8 | +) |
| 9 | + |
| 10 | +type Foo interface { |
| 11 | + Add(a int, b *int) int |
| 12 | +} |
| 13 | + |
| 14 | +type FooImpl struct { |
| 15 | +} |
| 16 | + |
| 17 | +func (*FooImpl) Add(a int, b *int) int { |
| 18 | + return 0 |
| 19 | +} |
| 20 | + |
| 21 | +type Env struct { |
| 22 | + Foo Foo `expr:"foo"` |
| 23 | +} |
| 24 | + |
| 25 | +func (Env) Any(x any) any { |
| 26 | + return x |
| 27 | +} |
| 28 | + |
| 29 | +func TestNoInterfaceMethodWithNil(t *testing.T) { |
| 30 | + program, err := expr.Compile(`foo.Add(1, nil)`) |
| 31 | + require.NoError(t, err) |
| 32 | + |
| 33 | + _, err = expr.Run(program, Env{Foo: &FooImpl{}}) |
| 34 | + require.NoError(t, err) |
| 35 | +} |
| 36 | + |
| 37 | +func TestNoInterfaceMethodWithNil_with_env(t *testing.T) { |
| 38 | + program, err := expr.Compile(`foo.Add(1, nil)`, expr.Env(Env{})) |
| 39 | + require.NoError(t, err) |
| 40 | + |
| 41 | + _, err = expr.Run(program, Env{Foo: &FooImpl{}}) |
| 42 | + require.NoError(t, err) |
| 43 | +} |
| 44 | + |
| 45 | +func TestNoInterfaceMethodWithNil_with_any(t *testing.T) { |
| 46 | + program, err := expr.Compile(`Any(nil)`, expr.Env(Env{})) |
| 47 | + require.NoError(t, err) |
| 48 | + |
| 49 | + out, err := expr.Run(program, Env{Foo: &FooImpl{}}) |
| 50 | + require.NoError(t, err) |
| 51 | + require.Equal(t, nil, out) |
| 52 | +} |
0 commit comments