fix: support for embedding alias of primitive types

fix #372
This commit is contained in:
Nao Yonashiro 2022-07-04 14:46:17 +09:00
parent 1468eefb01
commit f0e6a549f2
2 changed files with 26 additions and 0 deletions

View File

@ -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)
}
}

View File

@ -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{