From acc90c53e8b5448afee8455ee7c4917af25c6bc9 Mon Sep 17 00:00:00 2001 From: acanino Date: Fri, 21 Aug 2015 22:24:20 -0400 Subject: [PATCH] cmd/compile: Fix `internal compiler: getinarg: not a func` when returning invalid interface. Internal error arose from calling methodfunc on a invalid interface field during the implements check. int obviously isn't a function, and errors on getinarg... for im := iface.Type; im != nil; im = im.Down { imtype = methodfunc(im.Type, nil) // ... } Fix handles the internal compiler error, but does not throw an additional error, i.e. the following code will error on the I interface, but type A will pass the implements check since 'Read(string) string' is implemented and 'int' is skipped type I interface { Read(string) string int } type A struct { } func (a *A) Read(s string) string { return s } func New() I { return new(A) } Fixes #10975 Change-Id: I4b54013afb2814db3f315515f0c742d8631ca500 Reviewed-on: https://go-review.googlesource.com/13747 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/compile/internal/gc/subr.go | 3 +++ test/fixedbugs/issue10975.go | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 test/fixedbugs/issue10975.go diff --git a/src/cmd/compile/internal/gc/subr.go b/src/cmd/compile/internal/gc/subr.go index d2d51a0366..3280710b22 100644 --- a/src/cmd/compile/internal/gc/subr.go +++ b/src/cmd/compile/internal/gc/subr.go @@ -2986,6 +2986,9 @@ func implements(t *Type, iface *Type, m **Type, samename **Type, ptr *int) bool var followptr bool var rcvr *Type for im := iface.Type; im != nil; im = im.Down { + if im.Broke == 1 { + continue + } imtype = methodfunc(im.Type, nil) tm = ifacelookdot(im.Sym, t, &followptr, 0) if tm == nil || tm.Nointerface || !Eqtype(methodfunc(tm.Type, nil), imtype) { diff --git a/test/fixedbugs/issue10975.go b/test/fixedbugs/issue10975.go new file mode 100644 index 0000000000..0a4b7be2a8 --- /dev/null +++ b/test/fixedbugs/issue10975.go @@ -0,0 +1,19 @@ +// errorcheck + +// Copyright 2015 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. + +// Issue 10975: Returning an invalid interface would cause +// `internal compiler error: getinarg: not a func`. + +package main + +type I interface { + int // ERROR "interface contains embedded non-interface int" +} + +func New() I { + return struct{}{} +} + -- 2.48.1