]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: avoid n.Right nil dereference on non-existent interface methods
authorEmmanuel Odeke <emm.odeke@gmail.com>
Thu, 5 Jan 2017 02:21:13 +0000 (19:21 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 5 Jan 2017 22:09:25 +0000 (22:09 +0000)
Fixes #18392.

Avoid nil dereferencing n.Right when dealing with non-existent
self referenced interface methods e.g.
type A interface{
  Fn(A.Fn)
}

Instead, infer the symbol name from n.Sym itself.

Change-Id: I60d5f8988e7318693e5c8da031285d8d7347b771
Reviewed-on: https://go-review.googlesource.com/34817
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/typecheck.go
test/fixedbugs/issue18392.go [new file with mode: 0644]

index 23c60fa0d08260975c871994a73e67139f1047e8..5ec1c9e2f23e3845abcf61ac74629cff3c4b7bf7 100644 (file)
@@ -859,7 +859,7 @@ OpSwitch:
                        }
 
                        if n.Type.Etype != TFUNC || !n.IsMethod() {
-                               yyerror("type %v has no method %S", n.Left.Type, n.Right.Sym)
+                               yyerror("type %v has no method %S", n.Left.Type, n.Sym)
                                n.Type = nil
                                return n
                        }
diff --git a/test/fixedbugs/issue18392.go b/test/fixedbugs/issue18392.go
new file mode 100644 (file)
index 0000000..ad64238
--- /dev/null
@@ -0,0 +1,11 @@
+// errorcheck
+
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+type A interface {
+       Fn(A.Fn) // ERROR "type A has no method A.Fn"
+}