Skip to content

Commit

Permalink
Merge pull request #378 from orisano/fix/#372
Browse files Browse the repository at this point in the history
Fix embedded primitive type encoding using alias
  • Loading branch information
goccy committed Jul 5, 2022
2 parents 1468eef + f0e6a54 commit 554506d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions decode_test.go
Expand Up @@ -3968,3 +3968,20 @@ func TestIssue335(t *testing.T) {
t.Errorf("unexpected success")
}
}

func TestIssue372(t *testing.T) {
type A int
type T struct {
_ int
*A
}
var v T
err := json.Unmarshal([]byte(`{"A":7}`), &v)
assertErr(t, err)

got := *v.A
expected := A(7)
if got != expected {
t.Errorf("unexpected result: %v != %v", got, expected)
}
}
9 changes: 9 additions & 0 deletions internal/decoder/compile.go
Expand Up @@ -393,6 +393,15 @@ func compileStruct(typ *runtime.Type, structName, fieldName string, structTypeTo
}
allFields = append(allFields, fieldSet)
}
} else {
fieldSet := &structFieldSet{
dec: pdec,
offset: field.Offset,
isTaggedKey: tag.IsTaggedKey,
key: field.Name,
keyLen: int64(len(field.Name)),
}
allFields = append(allFields, fieldSet)
}
} else {
fieldSet := &structFieldSet{
Expand Down

0 comments on commit 554506d

Please sign in to comment.