File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package checker_test
22

33
import (
4+
"context"
45
"fmt"
56
"reflect"
67
"regexp"
@@ -1078,6 +1079,30 @@ func TestCheck_builtin_without_call(t *testing.T) {
10781079
}
10791080
}
10801081

1082+
func TestCheck_EmbeddedInterface(t *testing.T) {
1083+
t.Run("embedded interface lookup returns compile-error not panic", func(t *testing.T) {
1084+
type Env struct {
1085+
context.Context
1086+
Country string
1087+
}
1088+
type Wrapper struct {
1089+
Ctx Env
1090+
}
1091+
1092+
config := conf.New(Wrapper{
1093+
Ctx: Env{
1094+
Context: context.Background(),
1095+
Country: "TR",
1096+
},
1097+
})
1098+
expr.WithContext("Ctx")(config)
1099+
1100+
_, err := checker.ParseCheck("Ctx.C", config)
1101+
require.Error(t, err)
1102+
require.Contains(t, err.Error(), "has no field C")
1103+
})
1104+
}
1105+
10811106
func TestCheck_types(t *testing.T) {
10821107
env := types.Map{
10831108
"foo": types.Map{
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ func fieldName(field reflect.StructField) string {
1414
}
1515

1616
func fetchField(t reflect.Type, name string) (reflect.StructField, bool) {
17+
// If t is not a struct, early return.
18+
if t.Kind() != reflect.Struct {
19+
return reflect.StructField{}, false
20+
}
21+
1722
// First check all structs fields.
1823
for i := 0; i < t.NumField(); i++ {
1924
field := t.Field(i)

0 commit comments

Comments
 (0)