Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions checker/checker_test.go
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
package checker_test

import (
"context"
"fmt"
"reflect"
"regexp"
Expand DownExpand Up@@ -1078,6 +1079,30 @@ func TestCheck_builtin_without_call(t *testing.T) {
}
}

func TestCheck_EmbeddedInterface(t *testing.T) {
t.Run("embedded interface lookup returns compile-error not panic", func(t *testing.T) {
type Env struct {
context.Context
Country string
}
type Wrapper struct {
Ctx Env
}

config := conf.New(Wrapper{
Ctx: Env{
Context: context.Background(),
Country: "TR",
Comment thread
yigitkanbalci marked this conversation as resolved.
},
})
expr.WithContext("Ctx")(config)

_, err := checker.ParseCheck("Ctx.C", config)
require.Error(t, err)
require.Contains(t, err.Error(), "has no field C")
})
}

func TestCheck_types(t *testing.T) {
env := types.Map{
"foo": types.Map{
Expand Down
5 changes: 5 additions & 0 deletions checker/nature/utils.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,6 +14,11 @@ func fieldName(field reflect.StructField) string {
}

func fetchField(t reflect.Type, name string) (reflect.StructField, bool) {
// If t is not a struct, early return.
if t.Kind() != reflect.Struct {
return reflect.StructField{}, false
}

// First check all structs fields.
for i := 0; i < t.NumField(); i++ {
field := t.Field(i)
Expand Down