diff --git a/checker/nature/nature.go b/checker/nature/nature.go index 483030aa..ae406acb 100644 --- a/checker/nature/nature.go +++ b/checker/nature/nature.go @@ -404,8 +404,15 @@ func (n *Nature) getSlow(c *Cache, name string) (Nature, bool) { if nt, ok := n.MethodByName(c, name); ok { return nt, true } - if n.Kind == reflect.Struct { - if sf := n.structField(c, nil, name); sf != nil { + t, k, changed := deref.TypeKind(n.Type, n.Kind) + if k == reflect.Struct { + var sd *structData + if changed { + sd = c.getStruct(t).structData + } else { + sd = n.structData + } + if sf := sd.structField(c, nil, name); sf != nil { return sf.Nature, true } } diff --git a/test/issues/840/issue_test.go b/test/issues/840/issue_test.go index 1c0d3c95..abc00c3a 100644 --- a/test/issues/840/issue_test.go +++ b/test/issues/840/issue_test.go @@ -8,23 +8,28 @@ import ( ) func TestEnvFieldMethods(t *testing.T) { - program, err := expr.Compile(`Func(0)`, expr.Env(&Env{})) + program, err := expr.Compile(`Func() + Int`, expr.Env(&Env{})) require.NoError(t, err) env := &Env{} env.Func = func() int { - return 42 + return 40 + } + env.EmbeddedEnv = &EmbeddedEnv{ + Int: 2, } - out, err := expr.Run(program, Env{}) + out, err := expr.Run(program, env) require.NoError(t, err) require.Equal(t, 42, out) } type Env struct { - EmbeddedEnv + *EmbeddedEnv Func func() int } -type EmbeddedEnv struct{} +type EmbeddedEnv struct { + Int int +}