Skip to content

Commit

Permalink
fix: correctly resolve fields of aliased structs
Browse files Browse the repository at this point in the history
  • Loading branch information
secDre4mer committed Jan 7, 2025
1 parent e686f55 commit ae21de7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
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

0 comments on commit ae21de7

Please sign in to comment.