Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly resolve fields of aliased structs #1679

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions _test/type34.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

type original struct {
Field string
}

func main() {
type alias original
type alias2 alias
var a = &alias2{
Field: "test",
}
println(a.Field)
}

// Output:
// test
10 changes: 2 additions & 8 deletions interp/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2667,10 +2667,7 @@ func compositeBinSlice(n *node) {
func doCompositeBinStruct(n *node, hasType bool) {
next := getExec(n.tnext)
value := valueGenerator(n, n.findex)
typ := n.typ.rtype
if n.typ.cat == ptrT || n.typ.cat == linkedT {
typ = n.typ.val.rtype
}
typ := baseType(n.typ).rtype
child := n.child
if hasType {
child = n.child[1:]
Expand Down Expand Up @@ -2734,10 +2731,7 @@ func destType(n *node) *itype {
func doComposite(n *node, hasType bool, keyed bool) {
value := valueGenerator(n, n.findex)
next := getExec(n.tnext)
typ := n.typ
if typ.cat == ptrT || typ.cat == linkedT {
typ = typ.val
}
typ := baseType(n.typ)
child := n.child
if hasType {
child = n.child[1:]
Expand Down
5 changes: 1 addition & 4 deletions interp/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -1714,10 +1714,7 @@ func (t *itype) fieldIndex(name string) int {
func (t *itype) fieldSeq(seq []int) *itype {
ft := t
for _, i := range seq {
if ft.cat == ptrT {
ft = ft.val
}
ft = ft.field[i].typ
ft = baseType(ft).field[i].typ
}
return ft
}
Expand Down
Loading