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