Skip to content

Commit f616581

Browse files
secDre4mermvertes
andauthored
fix: correctly resolve fields of aliased structs (#1679)
Co-authored-by: Marc Vertes <mvertes@free.fr>
1 parent 1e3e91d commit f616581

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

_test/type34.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package main
2+
3+
type original struct {
4+
Field string
5+
}
6+
7+
func main() {
8+
type alias original
9+
type alias2 alias
10+
var a = &alias2{
11+
Field: "test",
12+
}
13+
println(a.Field)
14+
}
15+
16+
// Output:
17+
// test

interp/run.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2667,10 +2667,7 @@ func compositeBinSlice(n *node) {
26672667
func doCompositeBinStruct(n *node, hasType bool) {
26682668
next := getExec(n.tnext)
26692669
value := valueGenerator(n, n.findex)
2670-
typ := n.typ.rtype
2671-
if n.typ.cat == ptrT || n.typ.cat == linkedT {
2672-
typ = n.typ.val.rtype
2673-
}
2670+
typ := baseType(n.typ).rtype
26742671
child := n.child
26752672
if hasType {
26762673
child = n.child[1:]
@@ -2734,10 +2731,7 @@ func destType(n *node) *itype {
27342731
func doComposite(n *node, hasType bool, keyed bool) {
27352732
value := valueGenerator(n, n.findex)
27362733
next := getExec(n.tnext)
2737-
typ := n.typ
2738-
if typ.cat == ptrT || typ.cat == linkedT {
2739-
typ = typ.val
2740-
}
2734+
typ := baseType(n.typ)
27412735
child := n.child
27422736
if hasType {
27432737
child = n.child[1:]

interp/type.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,10 +1714,7 @@ func (t *itype) fieldIndex(name string) int {
17141714
func (t *itype) fieldSeq(seq []int) *itype {
17151715
ft := t
17161716
for _, i := range seq {
1717-
if ft.cat == ptrT {
1718-
ft = ft.val
1719-
}
1720-
ft = ft.field[i].typ
1717+
ft = baseType(ft).field[i].typ
17211718
}
17221719
return ft
17231720
}

0 commit comments

Comments
 (0)