aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChris Manghane <cmang@golang.org>2014-12-09 07:59:24 -0800
committerChris Manghane <cmang@golang.org>2015-02-25 19:27:30 +0000
commitb59dd94f331677d28250b51729d5bc888fe4cef0 (patch)
treedc72d777db996a4c2d0fec4d29185ff08fc9f1c1 /src
parent28c6648416362f8542adea03f70fccf77fc9b08e (diff)
downloadgo-b59dd94f331677d28250b51729d5bc888fe4cef0.tar.xz
cmd/internal/gc: method selector should not auto-deref named pointer type
Fixes #9017. Change-Id: I26cb1e7d6e137ff145773169cfe2d8bd4e1b339c Reviewed-on: https://go-review.googlesource.com/1252 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Chris Manghane <cmang@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/internal/gc/subr.go3
-rw-r--r--src/cmd/internal/gc/typecheck.go13
2 files changed, 16 insertions, 0 deletions
diff --git a/src/cmd/internal/gc/subr.go b/src/cmd/internal/gc/subr.go
index f7c0758400..9dc573e795 100644
--- a/src/cmd/internal/gc/subr.go
+++ b/src/cmd/internal/gc/subr.go
@@ -2172,6 +2172,9 @@ out:
// rebuild elided dots
for c := d - 1; c >= 0; c-- {
+ if n.Left.Type != nil && Isptr[n.Left.Type.Etype] != 0 {
+ n.Left.Implicit = 1
+ }
n.Left = Nod(ODOT, n.Left, newname(dotlist[c].field.Sym))
}
diff --git a/src/cmd/internal/gc/typecheck.go b/src/cmd/internal/gc/typecheck.go
index 9fa19300af..1468d5fb45 100644
--- a/src/cmd/internal/gc/typecheck.go
+++ b/src/cmd/internal/gc/typecheck.go
@@ -2433,6 +2433,19 @@ func lookdot(n *Node, t *Type, dostrcmp int) bool {
}
}
+ ll := n.Left
+ for ll.Left != nil {
+ ll = ll.Left
+ }
+ if ll.Implicit != 0 {
+ if Isptr[ll.Type.Etype] != 0 && ll.Type.Sym != nil && ll.Type.Sym.Def != nil && ll.Type.Sym.Def.Op == OTYPE {
+ // It is invalid to automatically dereference a named pointer type when selecting a method.
+ // Make n->left == ll to clarify error message.
+ n.Left = ll
+ return false
+ }
+ }
+
n.Right = methodname(n.Right, n.Left.Type)
n.Xoffset = f2.Width
n.Type = f2.Type