mirror of
https://github.com/golang/go
synced 2024-09-04 23:44:16 +00:00
cmd/gc: fix method values whose receiver is an unnamed interface.
Fixes #6140. R=golang-dev, iant CC=golang-dev https://golang.org/cl/13083043
This commit is contained in:
parent
65f21ca2c6
commit
a9e119ac70
|
@ -285,6 +285,8 @@ makepartialcall(Node *fn, Type *t0, Node *meth)
|
|||
NodeList *body, *l, *callargs, *retargs;
|
||||
char *p;
|
||||
Sym *sym;
|
||||
Pkg *spkg;
|
||||
static Pkg* gopkg;
|
||||
int i, ddd;
|
||||
|
||||
// TODO: names are not right
|
||||
|
@ -296,10 +298,18 @@ makepartialcall(Node *fn, Type *t0, Node *meth)
|
|||
basetype = rcvrtype;
|
||||
if(isptr[rcvrtype->etype])
|
||||
basetype = basetype->type;
|
||||
if(basetype->sym == S)
|
||||
if(basetype->etype != TINTER && basetype->sym == S)
|
||||
fatal("missing base type for %T", rcvrtype);
|
||||
|
||||
sym = pkglookup(p, basetype->sym->pkg);
|
||||
spkg = nil;
|
||||
if(basetype->sym != S)
|
||||
spkg = basetype->sym->pkg;
|
||||
if(spkg == nil) {
|
||||
if(gopkg == nil)
|
||||
gopkg = mkpkg(strlit("go"));
|
||||
spkg = gopkg;
|
||||
}
|
||||
sym = pkglookup(p, spkg);
|
||||
free(p);
|
||||
if(sym->flags & SymUniq)
|
||||
return sym->def;
|
||||
|
|
31
test/fixedbugs/issue6140.go
Normal file
31
test/fixedbugs/issue6140.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
// compile
|
||||
|
||||
// Copyright 2013 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 6140: compiler incorrectly rejects method values
|
||||
// whose receiver has an unnamed interface type.
|
||||
|
||||
package p
|
||||
|
||||
type T *interface {
|
||||
m() int
|
||||
}
|
||||
|
||||
var x T
|
||||
|
||||
var _ = (*x).m
|
||||
|
||||
var y interface {
|
||||
m() int
|
||||
}
|
||||
|
||||
var _ = y.m
|
||||
|
||||
type I interface {
|
||||
String() string
|
||||
}
|
||||
|
||||
var z *struct{ I }
|
||||
var _ = z.String
|
|
@ -21,7 +21,7 @@ func (p *P1) val() int { return 1 } // ERROR "receiver.* pointer|invalid pointer
|
|||
type I interface{}
|
||||
type I1 interface{}
|
||||
|
||||
func (p I) val() int { return 1 } // ERROR "receiver.*interface|invalid pointer or interface receiver"
|
||||
func (p I) val() int { return 1 } // ERROR "receiver.*interface|invalid pointer or interface receiver"
|
||||
func (p *I1) val() int { return 1 } // ERROR "receiver.*interface|invalid pointer or interface receiver"
|
||||
|
||||
type Val interface {
|
||||
|
@ -33,4 +33,5 @@ var _ = (*Val).val // ERROR "method"
|
|||
var v Val
|
||||
var pv = &v
|
||||
|
||||
var _ = pv.val() // ERROR "method"
|
||||
var _ = pv.val() // ERROR "method"
|
||||
var _ = pv.val // ERROR "method"
|
||||
|
|
Loading…
Reference in a new issue