File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 11package checker_test
22
33import (
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+
10811106func TestCheck_types (t * testing.T ) {
10821107 env := types.Map {
10831108 "foo" : types.Map {
Original file line number Diff line number Diff line change @@ -14,6 +14,11 @@ func fieldName(field reflect.StructField) string {
1414}
1515
1616func 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 )
You can’t perform that action at this time.
0 commit comments