mirror of
https://github.com/golang/go
synced 2024-11-18 10:14:45 -07:00
go/types: fix error message for embedded non-interface types in interfaces
Fixes #10979. Change-Id: Iac25645ba8181a56a75ddfcd29ff6d64c15c4f57 Reviewed-on: https://go-review.googlesource.com/10466 Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
3ba6387bd0
commit
ccc037699e
24
src/go/types/testdata/issues.src
vendored
24
src/go/types/testdata/issues.src
vendored
@ -71,3 +71,27 @@ func issue9473(a []int, b ...int) {
|
|||||||
append_(f0(), f1()... /* ERROR cannot use */ )
|
append_(f0(), f1()... /* ERROR cannot use */ )
|
||||||
append_(f0(), f2()... /* ERROR cannot use */ )
|
append_(f0(), f2()... /* ERROR cannot use */ )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that embedding a non-interface type in an interface results in a good error message.
|
||||||
|
func issue10979() {
|
||||||
|
type _ interface {
|
||||||
|
int /* ERROR int is not an interface */
|
||||||
|
}
|
||||||
|
type T struct{}
|
||||||
|
type _ interface {
|
||||||
|
T /* ERROR T is not an interface */
|
||||||
|
}
|
||||||
|
type _ interface {
|
||||||
|
nosuchtype /* ERROR undeclared name: nosuchtype */
|
||||||
|
}
|
||||||
|
type _ interface {
|
||||||
|
fmt /* ERROR Nosuchtype not declared by package fmt */ .Nosuchtype
|
||||||
|
}
|
||||||
|
type _ interface {
|
||||||
|
nosuchpkg /* ERROR undeclared name: nosuchpkg */ .Nosuchtype
|
||||||
|
}
|
||||||
|
type I interface {
|
||||||
|
I /* ERROR I\.m \(value of type func\(I\)\) is not a type */ .m
|
||||||
|
m()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -525,20 +525,14 @@ func (check *Checker) interfaceType(iface *Interface, ityp *ast.InterfaceType, d
|
|||||||
for _, e := range embedded {
|
for _, e := range embedded {
|
||||||
pos := e.Pos()
|
pos := e.Pos()
|
||||||
typ := check.typExpr(e, nil, path)
|
typ := check.typExpr(e, nil, path)
|
||||||
|
// Determine underlying embedded (possibly incomplete) type
|
||||||
|
// by following its forward chain.
|
||||||
named, _ := typ.(*Named)
|
named, _ := typ.(*Named)
|
||||||
if named == nil {
|
under := underlying(named)
|
||||||
if typ != Typ[Invalid] {
|
embed, _ := under.(*Interface)
|
||||||
check.invalidAST(pos, "%s is not named type", typ)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// determine underlying (possibly incomplete) type
|
|
||||||
// by following its forward chain
|
|
||||||
u := underlying(named)
|
|
||||||
embed, _ := u.(*Interface)
|
|
||||||
if embed == nil {
|
if embed == nil {
|
||||||
if u != Typ[Invalid] {
|
if typ != Typ[Invalid] {
|
||||||
check.errorf(pos, "%s is not an interface", named)
|
check.errorf(pos, "%s is not an interface", typ)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user