Skip to content

Commit

Permalink
cmd/compile: better error for embedded field referring to missing import
Browse files Browse the repository at this point in the history
Fixes #27938.

Change-Id: I16263ac6c0b8903b8a16f02e8db0e1a16d1c95b4
Reviewed-on: https://go-review.googlesource.com/c/144261
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
  • Loading branch information
griesemer committed Oct 24, 2018
1 parent 5a7cfbc commit 5538eca
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/cmd/compile/internal/gc/noder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
23 changes: 23 additions & 0 deletions test/fixedbugs/issue27938.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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"
}

0 comments on commit 5538eca

Please sign in to comment.