Skip to content

Commit 17f83e3

Browse files
griesemerRobert Griesemer
authored and
Robert Griesemer
committed
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 <[email protected]> Run-TryBot: Robert Findley <[email protected]> Reviewed-by: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 2da95e0 commit 17f83e3

File tree

4 files changed

+6
-10
lines changed

4 files changed

+6
-10
lines changed

src/cmd/compile/internal/types2/call.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -465,19 +465,15 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, def *Named) {
465465
}
466466
}
467467
if exp == nil {
468-
check.errorf(e.Sel, _UndeclaredImportedName, "%s not declared by package C", sel)
468+
check.errorf(e.Sel, _UndeclaredImportedName, "undefined: %s", syntax.Expr(e)) // cast to syntax.Expr to silence vet
469469
goto Error
470470
}
471471
check.objDecl(exp, nil)
472472
} else {
473473
exp = pkg.scope.Lookup(sel)
474474
if exp == nil {
475475
if !pkg.fake {
476-
if check.conf.CompilerErrorMessages {
477-
check.errorf(e.Sel, _UndeclaredImportedName, "undefined: %s.%s", pkg.name, sel)
478-
} else {
479-
check.errorf(e.Sel, _UndeclaredImportedName, "%s not declared by package %s", sel, pkg.name)
480-
}
476+
check.errorf(e.Sel, _UndeclaredImportedName, "undefined: %s", syntax.Expr(e))
481477
}
482478
goto Error
483479
}

src/go/types/call.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,15 +469,15 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, def *Named) {
469469
}
470470
}
471471
if exp == nil {
472-
check.errorf(e.Sel, _UndeclaredImportedName, "%s not declared by package C", sel)
472+
check.errorf(e.Sel, _UndeclaredImportedName, "undefined: %s", ast.Expr(e)) // cast to ast.Expr to silence vet
473473
goto Error
474474
}
475475
check.objDecl(exp, nil)
476476
} else {
477477
exp = pkg.scope.Lookup(sel)
478478
if exp == nil {
479479
if !pkg.fake {
480-
check.errorf(e.Sel, _UndeclaredImportedName, "%s not declared by package %s", sel, pkg.name)
480+
check.errorf(e.Sel, _UndeclaredImportedName, "undefined: %s", ast.Expr(e))
481481
}
482482
goto Error
483483
}

src/internal/types/testdata/check/decls1.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ var (
6464
t13 int = a /* ERROR "shifted operand" */ << d
6565
t14 int = i << j
6666
t15 math /* ERROR "not in selector" */
67-
t16 math.xxx /* ERROR "not declared" */
67+
t16 math.xxx /* ERROR "undefined" */
6868
t17 math /* ERROR "not a type" */ .Pi
6969
t18 float64 = math.Pi * 10.0
7070
t19 int = t1 /* ERROR "cannot call" */ ()

src/internal/types/testdata/check/issues0.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func issue10979() {
9191
nosuchtype /* ERROR undefined: nosuchtype */
9292
}
9393
type _ interface {
94-
fmt.Nosuchtype /* ERROR Nosuchtype not declared by package fmt */
94+
fmt.Nosuchtype /* ERROR undefined: fmt\.Nosuchtype */
9595
}
9696
type _ interface {
9797
nosuchpkg /* ERROR undefined: nosuchpkg */ .Nosuchtype

0 commit comments

Comments
 (0)