Skip to content

Commit 0675733

Browse files
committed
Fix nil type checks
1 parent bbf30b4 commit 0675733

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Diff for: checker/checker_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -733,3 +733,15 @@ func TestCheck_CallFastTyped_Method(t *testing.T) {
733733
require.False(t, tree.Node.(*ast.CallNode).Fast)
734734
require.Equal(t, 42, tree.Node.(*ast.CallNode).Typed)
735735
}
736+
737+
func TestCheck_works_with_nil_types(t *testing.T) {
738+
env := map[string]interface{}{
739+
"null": nil,
740+
}
741+
742+
tree, err := parser.Parse("null")
743+
require.NoError(t, err)
744+
745+
_, err = checker.Check(tree, conf.New(env))
746+
require.NoError(t, err)
747+
}

Diff for: checker/types.go

+3
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ func fetchField(t reflect.Type, name string) (reflect.StructField, bool) {
204204
}
205205

206206
func deref(t reflect.Type) (reflect.Type, bool) {
207+
if t == nil {
208+
return nil, false
209+
}
207210
if t.Kind() == reflect.Interface {
208211
return t, true
209212
}

0 commit comments

Comments
 (0)