Commit 5538ecad authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile: better error for embedded field referring to missing import

Fixes #27938.

Change-Id: I16263ac6c0b8903b8a16f02e8db0e1a16d1c95b4
Reviewed-on: https://go-review.googlesource.com/c/144261Reviewed-by: 's avatarMatthew Dempsky <mdempsky@google.com>
parent 5a7cfbc0
......@@ -819,13 +819,18 @@ func (p *noder) packname(expr syntax.Expr) *types.Sym {
return name
case *syntax.SelectorExpr:
name := p.name(expr.X.(*syntax.Name))
def := asNode(name.Def)
if def == nil {
yyerror("undefined: %v", name)
return name
}
var pkg *types.Pkg
if asNode(name.Def) == nil || asNode(name.Def).Op != OPACK {
if def.Op != OPACK {
yyerror("%v is not a package", name)
pkg = localpkg
} else {
asNode(name.Def).Name.SetUsed(true)
pkg = asNode(name.Def).Name.Pkg
def.Name.SetUsed(true)
pkg = def.Name.Pkg
}
return restrictlookup(expr.Sel.Value, pkg)
}
......
// errorcheck
// Copyright 2018 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.
// Verify that we get a single non-confusing error
// message for embedded fields/interfaces that use
// a qualified identifier with non-existing package.
package p
type _ struct {
F sync.Mutex // ERROR "undefined: sync"
}
type _ struct {
sync.Mutex // ERROR "undefined: sync"
}
type _ interface {
sync.Mutex // ERROR "undefined: sync"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment