Skip to content

Commit edd09e7

Browse files
committed
Fix encoding of using empty interface as map key
1 parent ad04977 commit edd09e7

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

encode_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,3 +1912,9 @@ func TestIssue235(t *testing.T) {
19121912
t.Fatal(err)
19131913
}
19141914
}
1915+
1916+
func TestEncodeMapKeyTypeInterface(t *testing.T) {
1917+
if _, err := json.Marshal(map[interface{}]interface{}{"a": 1}); err == nil {
1918+
t.Fatal("expected error")
1919+
}
1920+
}

internal/encoder/compiler.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,6 @@ func compileKey(ctx *compileContext) (*Opcode, error) {
486486
switch typ.Kind() {
487487
case reflect.Ptr:
488488
return compilePtr(ctx)
489-
case reflect.Interface:
490-
return compileInterface(ctx)
491489
case reflect.String:
492490
return compileString(ctx)
493491
case reflect.Int:

0 commit comments

Comments
 (0)