From 6b4ca5231f41c9dc51dc3bc1bb05f30626b43444 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Mon, 6 Nov 2023 09:22:54 -0800 Subject: [PATCH] nil receiver --- optional_unmarshaljson.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/optional_unmarshaljson.go b/optional_unmarshaljson.go index 7f7c8cd..001dc45 100644 --- a/optional_unmarshaljson.go +++ b/optional_unmarshaljson.go @@ -6,11 +6,17 @@ import ( "sourcecode.social/reiver/go-erorr" ) +const errNilReceiver = erorr.Error("opt: nil receiver") + var _ json.Unmarshaler = new(Optional[bool]) var _ json.Unmarshaler = new(Optional[string]) // UnmarshalJSON makes it so json.Unmarshaler is implemented. func (receiver *Optional[T]) UnmarshalJSON(data []byte) error { + if nil == receiver { + return errNilReceiver + } + switch interface{}(&receiver.value).(type) { case *bool, *string, json.Unmarshaler: // these are OK.