diff options
Diffstat (limited to 'libgo/go/encoding/gob/encoder_test.go')
-rw-r--r-- | libgo/go/encoding/gob/encoder_test.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/libgo/go/encoding/gob/encoder_test.go b/libgo/go/encoding/gob/encoder_test.go index 22090a18a6f..9256848b50e 100644 --- a/libgo/go/encoding/gob/encoder_test.go +++ b/libgo/go/encoding/gob/encoder_test.go @@ -830,6 +830,20 @@ func TestPtrToMapOfMap(t *testing.T) { } } +// Test that untyped nils generate an error, not a panic. +// See Issue 16204. +func TestCatchInvalidNilValue(t *testing.T) { + encodeErr, panicErr := encodeAndRecover(nil) + if panicErr != nil { + t.Fatalf("panicErr=%v, should not panic encoding untyped nil", panicErr) + } + if encodeErr == nil { + t.Errorf("got err=nil, want non-nil error when encoding untyped nil value") + } else if !strings.Contains(encodeErr.Error(), "nil value") { + t.Errorf("expected 'nil value' error; got err=%v", encodeErr) + } +} + // A top-level nil pointer generates a panic with a helpful string-valued message. func TestTopLevelNilPointer(t *testing.T) { var ip *int |