Skip to content

Commit 438a71b

Browse files
secDre4mermvertes
authored andcommitted
fix: correctly resolve fields of aliased structs (traefik#1679)
Co-authored-by: Marc Vertes <mvertes@free.fr>
1 parent ee10458 commit 438a71b

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
@@ -2662,10 +2662,7 @@ func compositeBinSlice(n *node) {
26622662
func doCompositeBinStruct(n *node, hasType bool) {
26632663
next := getExec(n.tnext)
26642664
value := valueGenerator(n, n.findex)
2665-
typ := n.typ.rtype
2666-
if n.typ.cat == ptrT || n.typ.cat == linkedT {
2667-
typ = n.typ.val.rtype
2668-
}
2665+
typ := baseType(n.typ).rtype
26692666
child := n.child
26702667
if hasType {
26712668
child = n.child[1:]
@@ -2729,10 +2726,7 @@ func destType(n *node) *itype {
27292726
func doComposite(n *node, hasType bool, keyed bool) {
27302727
value := valueGenerator(n, n.findex)
27312728
next := getExec(n.tnext)
2732-
typ := n.typ
2733-
if typ.cat == ptrT || typ.cat == linkedT {
2734-
typ = typ.val
2735-
}
2729+
typ := baseType(n.typ)
27362730
child := n.child
27372731
if hasType {
27382732
child = n.child[1:]

interp/type.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,10 +1720,7 @@ func (t *itype) fieldIndex(name string) int {
17201720
func (t *itype) fieldSeq(seq []int) *itype {
17211721
ft := t
17221722
for _, i := range seq {
1723-
if ft.cat == ptrT {
1724-
ft = ft.val
1725-
}
1726-
ft = ft.field[i].typ
1723+
ft = baseType(ft).field[i].typ
17271724
}
17281725
return ft
17291726
}

0 commit comments

Comments
 (0)