Skip to content

Commit

Permalink
Fix nil type checks
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Jan 22, 2023
1 parent bbf30b4 commit 0675733
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions checker/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,3 +733,15 @@ func TestCheck_CallFastTyped_Method(t *testing.T) {
require.False(t, tree.Node.(*ast.CallNode).Fast)
require.Equal(t, 42, tree.Node.(*ast.CallNode).Typed)
}

func TestCheck_works_with_nil_types(t *testing.T) {
env := map[string]interface{}{
"null": nil,
}

tree, err := parser.Parse("null")
require.NoError(t, err)

_, err = checker.Check(tree, conf.New(env))
require.NoError(t, err)
}
3 changes: 3 additions & 0 deletions checker/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ func fetchField(t reflect.Type, name string) (reflect.StructField, bool) {
}

func deref(t reflect.Type) (reflect.Type, bool) {
if t == nil {
return nil, false
}
if t.Kind() == reflect.Interface {
return t, true
}
Expand Down

0 comments on commit 0675733

Please sign in to comment.