Skip to content

Commit

Permalink
go.exp/go/types: better error message for non-existing qualified idents
Browse files Browse the repository at this point in the history
Fixes golang/go#4967.

R=golang-dev, r, remyoudompheng
CC=golang-dev
https://golang.org/cl/8092048
  • Loading branch information
griesemer committed Apr 1, 2013
1 parent 6189a9d commit 233982a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions go/types/expr.go
Expand Up @@ -1145,11 +1145,14 @@ func (check *checker) rawExpr(x *operand, e ast.Expr, hint Type, iota int, cycle
if ident, ok := e.X.(*ast.Ident); ok {
if pkg, ok := check.lookup(ident).(*Package); ok {
exp := pkg.Scope.Lookup(sel)
// gcimported package scopes contain non-exported
// objects such as types used in partially exported
// objects - do not accept them
if exp == nil || !ast.IsExported(exp.GetName()) {
check.errorf(e.Pos(), "cannot refer to unexported %s", e)
if exp == nil {
check.errorf(e.Pos(), "%s not declared by package %s", sel, ident)
goto Error
} else if !ast.IsExported(exp.GetName()) {
// gcimported package scopes contain non-exported
// objects such as types used in partially exported
// objects - do not accept them
check.errorf(e.Pos(), "%s not exported by package %s", sel, ident)
goto Error
}
check.register(e.Sel, exp)
Expand Down
2 changes: 1 addition & 1 deletion go/types/testdata/decls0.src
Expand Up @@ -18,7 +18,7 @@ import (

// reflect.flag must not be visible in this package
type flag int
type _ reflect /* ERROR "cannot refer to unexported" */ .flag
type _ reflect /* ERROR "not exported" */ .flag

// dot-imported exported objects may conflict with local objects
type Value /* ERROR "redeclared in this block by dot-import" */ struct{}
Expand Down
2 changes: 1 addition & 1 deletion go/types/testdata/decls1.src
Expand Up @@ -64,7 +64,7 @@ var (
t13 int = a /* ERROR "shifted operand" */ << d
t14 int = i << j /* ERROR "must be unsigned" */
t15 math /* ERROR "not in selector" */
t16 math /* ERROR "unexported" */ .xxx
t16 math /* ERROR "not declared" */ .xxx
t17 math /* ERROR "not a type" */ .Pi
t18 float64 = math.Pi * 10.0
t19 int = t1 /* ERROR "cannot call" */ ()
Expand Down

0 comments on commit 233982a

Please sign in to comment.