File tree
Expand file treeCollapse file tree2 files changed
+30
-0
lines changed Expand file treeCollapse file tree2 files changed
+30
-0
lines changed Original file line number | Diff line number | Diff line change |
---|
|
1 | 1 | package checker_test
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | +"context" |
4 | 5 | "fmt"
|
5 | 6 | "reflect"
|
6 | 7 | "regexp"
|
@@ -1078,6 +1079,30 @@ func TestCheck_builtin_without_call(t *testing.T) {
|
1078 | 1079 | }
|
1079 | 1080 | }
|
1080 | 1081 |
|
| 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 | + |
1081 | 1106 | func TestCheck_types(t *testing.T) {
|
1082 | 1107 | env := types.Map{
|
1083 | 1108 | "foo": types.Map{
|
|
Original file line number | Diff line number | Diff line change |
---|
@@ -14,6 +14,11 @@ func fieldName(field reflect.StructField) string {
|
14 | 14 | }
|
15 | 15 |
|
16 | 16 | 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 | + |
17 | 22 | // First check all structs fields.
|
18 | 23 | for i := 0; i < t.NumField(); i++ {
|
19 | 24 | field := t.Field(i)
|
|
You can’t perform that action at this time.
0 commit comments