]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: report "undefined: p.x" instead of "x not declared by package p"
authorRobert Griesemer <gri@golang.org>
Wed, 21 Sep 2022 20:30:18 +0000 (13:30 -0700)
committerRobert Griesemer <gri@google.com>
Mon, 26 Sep 2022 23:54:36 +0000 (23:54 +0000)
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>

src/cmd/compile/internal/types2/call.go
src/go/types/call.go
src/internal/types/testdata/check/decls1.go
src/internal/types/testdata/check/issues0.go

index 87b29d7260c6ab0a3ea9878523b7c74c9bfc34a2..fb7d5ec553ff41c8fbc4eebe697d2fc47a353174 100644 (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
                                }
index c580885a5ab16bec67eb1b4a722b15cf12aba476..ab0aea69bf469d16aecc3220b050ab69bd23491c 100644 (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
                                }
index 4052c869257bfd127780bdcdf707bf4c473692f2..c1bdf3cf9160a154c6bead9f65fbf1893c060a29 100644 (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" */ ()
index 8e277a7177fb8af81f7ed813d5b824f62a6ea8af..fc0c028276ec96f7720b1c52c39a50fa7c93fb42 100644 (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