go/types, types2: report "undefined: p.x" instead of "x not declared by package p"

This matches the compiler's long-standing behavior.

For #55326.

Change-Id: Icd946b031b1b6e65498fb52bceb4a53807732463
Reviewed-on: https://go-review.googlesource.com/c/go/+/432556
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Robert Griesemer 2022-09-21 13:30:18 -07:00 committed by Robert Griesemer
parent 2da95e0ec8
commit 17f83e3473
4 changed files with 6 additions and 10 deletions

View File

@ -465,7 +465,7 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, def *Named) {
}
}
if exp == nil {
check.errorf(e.Sel, _UndeclaredImportedName, "%s not declared by package C", sel)
check.errorf(e.Sel, _UndeclaredImportedName, "undefined: %s", syntax.Expr(e)) // cast to syntax.Expr to silence vet
goto Error
}
check.objDecl(exp, nil)
@ -473,11 +473,7 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, def *Named) {
exp = pkg.scope.Lookup(sel)
if exp == nil {
if !pkg.fake {
if check.conf.CompilerErrorMessages {
check.errorf(e.Sel, _UndeclaredImportedName, "undefined: %s.%s", pkg.name, sel)
} else {
check.errorf(e.Sel, _UndeclaredImportedName, "%s not declared by package %s", sel, pkg.name)
}
check.errorf(e.Sel, _UndeclaredImportedName, "undefined: %s", syntax.Expr(e))
}
goto Error
}

View File

@ -469,7 +469,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, def *Named) {
}
}
if exp == nil {
check.errorf(e.Sel, _UndeclaredImportedName, "%s not declared by package C", sel)
check.errorf(e.Sel, _UndeclaredImportedName, "undefined: %s", ast.Expr(e)) // cast to ast.Expr to silence vet
goto Error
}
check.objDecl(exp, nil)
@ -477,7 +477,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, def *Named) {
exp = pkg.scope.Lookup(sel)
if exp == nil {
if !pkg.fake {
check.errorf(e.Sel, _UndeclaredImportedName, "%s not declared by package %s", sel, pkg.name)
check.errorf(e.Sel, _UndeclaredImportedName, "undefined: %s", ast.Expr(e))
}
goto Error
}

View File

@ -64,7 +64,7 @@ var (
t13 int = a /* ERROR "shifted operand" */ << d
t14 int = i << j
t15 math /* ERROR "not in selector" */
t16 math.xxx /* ERROR "not declared" */
t16 math.xxx /* ERROR "undefined" */
t17 math /* ERROR "not a type" */ .Pi
t18 float64 = math.Pi * 10.0
t19 int = t1 /* ERROR "cannot call" */ ()

View File

@ -91,7 +91,7 @@ func issue10979() {
nosuchtype /* ERROR undefined: nosuchtype */
}
type _ interface {
fmt.Nosuchtype /* ERROR Nosuchtype not declared by package fmt */
fmt.Nosuchtype /* ERROR undefined: fmt\.Nosuchtype */
}
type _ interface {
nosuchpkg /* ERROR undefined: nosuchpkg */ .Nosuchtype