From edd09e74708e1c07feb7f09b1d64a5116553157c Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Sun, 6 Jun 2021 20:39:49 +0900 Subject: [PATCH] Fix encoding of using empty interface as map key --- encode_test.go | 6 ++++++ internal/encoder/compiler.go | 2 -- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/encode_test.go b/encode_test.go index b2e5ec4..715bf4f 100644 --- a/encode_test.go +++ b/encode_test.go @@ -1912,3 +1912,9 @@ func TestIssue235(t *testing.T) { t.Fatal(err) } } + +func TestEncodeMapKeyTypeInterface(t *testing.T) { + if _, err := json.Marshal(map[interface{}]interface{}{"a": 1}); err == nil { + t.Fatal("expected error") + } +} diff --git a/internal/encoder/compiler.go b/internal/encoder/compiler.go index f9937a4..56a9604 100644 --- a/internal/encoder/compiler.go +++ b/internal/encoder/compiler.go @@ -486,8 +486,6 @@ func compileKey(ctx *compileContext) (*Opcode, error) { switch typ.Kind() { case reflect.Ptr: return compilePtr(ctx) - case reflect.Interface: - return compileInterface(ctx) case reflect.String: return compileString(ctx) case reflect.Int: