diff --git a/inject.go b/inject.go index 300b9a3..f2d0b95 100644 --- a/inject.go +++ b/inject.go @@ -563,7 +563,7 @@ func parseTag(t string) (*tag, error) { } func isStructPtr(t reflect.Type) bool { - return t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Struct + return t != nil && t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Struct } func isNilOrZero(v reflect.Value, t reflect.Type) bool { diff --git a/inject_test.go b/inject_test.go index 6433eed..d4daa50 100644 --- a/inject_test.go +++ b/inject_test.go @@ -994,3 +994,13 @@ func TestForSameNameButDifferentPackage(t *testing.T) { t.Fatal(err) } } + +func TestInjectNil(t *testing.T) { + var g inject.Graph + err := g.Provide( + &inject.Object{Value: nil}, + ) + if err == nil { + t.Fatal("expected error when injecting nil") + } +}