[go] cmd/compile: use `"pkg" imported [as X] but not used` error message

37 views
Skip to first unread message

Robert Griesemer (Gerrit)

unread,
Sep 21, 2022, 5:30:27 PM9/21/22
to goph...@pubsubhelper.golang.org, Robert Griesemer, golang-co...@googlegroups.com

Robert Griesemer has uploaded this change for review.

View Change

cmd/compile: use `"pkg" imported [as X] but not used` error message

This matches the existing `X declared but not used` error.

For #55326.

Change-Id: Ie71cf662fb5f4648449c64fc51bede298a1bdcbf
---
M src/cmd/compile/internal/types2/resolver.go
M src/go/types/resolver.go
M src/internal/types/testdata/check/importdecl0/importdecl0a.go
M test/fixedbugs/issue11361.go
M test/fixedbugs/issue20298.go
M test/fixedbugs/issue5957.dir/c.go
M test/fixedbugs/issue6428.go
M test/import1.go
M test/import4.dir/import4.go
9 files changed, 44 insertions(+), 39 deletions(-)

diff --git a/src/cmd/compile/internal/types2/resolver.go b/src/cmd/compile/internal/types2/resolver.go
index 5301b64..bf88c81 100644
--- a/src/cmd/compile/internal/types2/resolver.go
+++ b/src/cmd/compile/internal/types2/resolver.go
@@ -726,17 +726,9 @@
elem = elem[i+1:]
}
if obj.name == "" || obj.name == "." || obj.name == elem {
- if check.conf.CompilerErrorMessages {
- check.softErrorf(obj, _UnusedImport, "imported and not used: %q", path)
- } else {
- check.softErrorf(obj, _UnusedImport, "%q imported but not used", path)
- }
+ check.softErrorf(obj, _UnusedImport, "%q imported but not used", path)
} else {
- if check.conf.CompilerErrorMessages {
- check.softErrorf(obj, _UnusedImport, "imported and not used: %q as %s", path, obj.name)
- } else {
- check.softErrorf(obj, _UnusedImport, "%q imported but not used as %s", path, obj.name)
- }
+ check.softErrorf(obj, _UnusedImport, "%q imported as %s but not used", path, obj.name)
}
}

diff --git a/src/go/types/resolver.go b/src/go/types/resolver.go
index 12ec55a..c7d698b 100644
--- a/src/go/types/resolver.go
+++ b/src/go/types/resolver.go
@@ -708,7 +708,7 @@
if obj.name == "" || obj.name == "." || obj.name == elem {
check.softErrorf(obj, _UnusedImport, "%q imported but not used", path)
} else {
- check.softErrorf(obj, _UnusedImport, "%q imported but not used as %s", path, obj.name)
+ check.softErrorf(obj, _UnusedImport, "%q imported as %s but not used", path, obj.name)
}
}

diff --git a/src/internal/types/testdata/check/importdecl0/importdecl0a.go b/src/internal/types/testdata/check/importdecl0/importdecl0a.go
index 5ceb96e..285d2e5 100644
--- a/src/internal/types/testdata/check/importdecl0/importdecl0a.go
+++ b/src/internal/types/testdata/check/importdecl0/importdecl0a.go
@@ -17,12 +17,12 @@
)

import "math" /* ERROR "imported but not used" */
-import m /* ERROR "imported but not used as m" */ "math"
+import m /* ERROR "imported as m but not used" */ "math"
import _ "math"

import (
"math/big" /* ERROR "imported but not used" */
- b /* ERROR "imported but not used" */ "math/big"
+ b /* ERROR "imported as b but not used" */ "math/big"
_ "math/big"
)

diff --git a/test/fixedbugs/issue11361.go b/test/fixedbugs/issue11361.go
index 1ef8735..105329f 100644
--- a/test/fixedbugs/issue11361.go
+++ b/test/fixedbugs/issue11361.go
@@ -6,6 +6,6 @@

package a

-import "fmt" // GC_ERROR "imported and not used"
+import "fmt" // GC_ERROR "imported and not used|imported but not used"

const n = fmt // ERROR "fmt without selector|unexpected reference to package|use of package fmt not in selector"
diff --git a/test/fixedbugs/issue20298.go b/test/fixedbugs/issue20298.go
index 7572a6b..ea33ee8 100644
--- a/test/fixedbugs/issue20298.go
+++ b/test/fixedbugs/issue20298.go
@@ -11,16 +11,16 @@
package p

import (
- "bufio" // ERROR "imported and not used"
- "bytes" // ERROR "imported and not used"
- "crypto/x509" // ERROR "imported and not used"
- "flag" // ERROR "imported and not used"
- "fmt" // ERROR "imported and not used"
- "io" // ERROR "imported and not used"
- "io/ioutil" // ERROR "imported and not used"
- "log" // ERROR "imported and not used"
- "math" // ERROR "imported and not used"
- "math/big" // ERROR "imported and not used" "too many errors"
+ "bufio" // ERROR "imported (and|but) not used"
+ "bytes" // ERROR "imported (and|but) not used"
+ "crypto/x509" // ERROR "imported (and|but) not used"
+ "flag" // ERROR "imported (and|but) not used"
+ "fmt" // ERROR "imported (and|but) not used"
+ "io" // ERROR "imported (and|but) not used"
+ "io/ioutil" // ERROR "imported (and|but) not used"
+ "log" // ERROR "imported (and|but) not used"
+ "math" // ERROR "imported (and|but) not used"
+ "math/big" // ERROR "imported (and|but) not used" "too many errors"
"math/bits"
"net"
"net/http"
diff --git a/test/fixedbugs/issue5957.dir/c.go b/test/fixedbugs/issue5957.dir/c.go
index 821b37e..9d8196f 100644
--- a/test/fixedbugs/issue5957.dir/c.go
+++ b/test/fixedbugs/issue5957.dir/c.go
@@ -1,12 +1,12 @@
package p

import (
- "./a" // ERROR "imported and not used: \x22test/a\x22 as surprise|imported and not used: surprise"
- "./b" // ERROR "imported and not used: \x22test/b\x22 as surprise2|imported and not used: surprise2"
- b "./b" // ERROR "imported and not used: \x22test/b\x22$|imported and not used: surprise2"
- foo "math" // ERROR "imported and not used: \x22math\x22 as foo|imported and not used: math"
+ "./a" // ERROR "imported and not used: \x22test/a\x22 as surprise|imported and not used: surprise|\x22test/a\x22 imported as surprise but not used"
+ "./b" // ERROR "imported and not used: \x22test/b\x22 as surprise2|imported and not used: surprise2|\x22test/b\x22 imported as surprise2 but not used"
+ b "./b" // ERROR "imported and not used: \x22test/b\x22$|imported and not used: surprise2|\x22test/b\x22 imported but not used"
+ foo "math" // ERROR "imported and not used: \x22math\x22 as foo|imported and not used: math|\x22math\x22 imported as foo but not used"
"fmt" // actually used
- "strings" // ERROR "imported and not used: \x22strings\x22|imported and not used: strings"
+ "strings" // ERROR "imported and not used: \x22strings\x22|imported and not used: strings|\x22strings\x22 imported but not used"
)

var _ = fmt.Printf
diff --git a/test/fixedbugs/issue6428.go b/test/fixedbugs/issue6428.go
index c3f7b20..4170e26 100644
--- a/test/fixedbugs/issue6428.go
+++ b/test/fixedbugs/issue6428.go
@@ -6,7 +6,7 @@

package p

-import . "testing" // ERROR "imported and not used"
+import . "testing" // ERROR "imported and not used|imported but not used"

type S struct {
T int
diff --git a/test/import1.go b/test/import1.go
index 294ef3a..5c5c323 100644
--- a/test/import1.go
+++ b/test/import1.go
@@ -10,10 +10,10 @@
package main

import "bufio" // ERROR "previous|not used"
-import bufio "os" // ERROR "redeclared|redefinition|incompatible" "imported and not used"
+import bufio "os" // ERROR "redeclared|redefinition|incompatible" "imported and not used|imported as bufio but not used"

import (
"fmt" // ERROR "previous|not used"
- fmt "math" // ERROR "redeclared|redefinition|incompatible" "imported and not used: \x22math\x22 as fmt"
- . "math" // GC_ERROR "imported and not used: \x22math\x22$"
+ fmt "math" // ERROR "redeclared|redefinition|incompatible" "imported and not used: \x22math\x22 as fmt|imported as fmt but not used"
+ . "math" // GC_ERROR "imported and not used: \x22math\x22$|imported but not used"
)
diff --git a/test/import4.dir/import4.go b/test/import4.dir/import4.go
index b9f973f..c553253 100644
--- a/test/import4.dir/import4.go
+++ b/test/import4.dir/import4.go
@@ -9,16 +9,16 @@
package main

// standard
-import "fmt" // ERROR "imported and not used.*fmt"
+import "fmt" // ERROR "imported and not used.*fmt|\x22fmt\x22 imported but not used"

// renamed
-import X "math" // ERROR "imported and not used.*math"
+import X "math" // ERROR "imported and not used.*math|\x22math\x22 imported as X but not used"

// import dot
-import . "bufio" // ERROR "imported and not used.*bufio"
+import . "bufio" // ERROR "imported and not used.*bufio|imported but not used"

// again, package without anything in it
-import "./empty" // ERROR "imported and not used.*empty"
-import Z "./empty" // ERROR "imported and not used.*empty"
-import . "./empty" // ERROR "imported and not used.*empty"
+import "./empty" // ERROR "imported and not used.*empty|imported but not used"
+import Z "./empty" // ERROR "imported and not used.*empty|imported as Z but not used"
+import . "./empty" // ERROR "imported and not used.*empty|imported but not used"


To view, visit change 432557. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ie71cf662fb5f4648449c64fc51bede298a1bdcbf
Gerrit-Change-Number: 432557
Gerrit-PatchSet: 1
Gerrit-Owner: Robert Griesemer <g...@golang.org>
Gerrit-MessageType: newchange

Robert Griesemer (Gerrit)

unread,
Sep 21, 2022, 5:36:40 PM9/21/22
to Robert Griesemer, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Attention is currently required from: Robert Griesemer.

Patch set 1:Run-TryBot +1

View Change

    To view, visit change 432557. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ie71cf662fb5f4648449c64fc51bede298a1bdcbf
    Gerrit-Change-Number: 432557
    Gerrit-PatchSet: 1
    Gerrit-Owner: Robert Griesemer <g...@golang.org>
    Gerrit-Reviewer: Robert Griesemer <g...@google.com>
    Gerrit-Attention: Robert Griesemer <g...@golang.org>
    Gerrit-Comment-Date: Wed, 21 Sep 2022 21:36:35 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Robert Griesemer (Gerrit)

    unread,
    Sep 21, 2022, 5:55:49 PM9/21/22
    to Robert Griesemer, goph...@pubsubhelper.golang.org, Robert Findley, Gopher Robot, golang-co...@googlegroups.com

    Attention is currently required from: Robert Findley, Robert Griesemer.

    Patch set 1:Code-Review +1

    View Change

      To view, visit change 432557. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ie71cf662fb5f4648449c64fc51bede298a1bdcbf
      Gerrit-Change-Number: 432557
      Gerrit-PatchSet: 1
      Gerrit-Owner: Robert Griesemer <g...@golang.org>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      Gerrit-Reviewer: Robert Findley <rfin...@google.com>
      Gerrit-Reviewer: Robert Griesemer <g...@google.com>
      Gerrit-Attention: Robert Findley <rfin...@google.com>
      Gerrit-Attention: Robert Griesemer <g...@golang.org>
      Gerrit-Comment-Date: Wed, 21 Sep 2022 21:55:44 +0000

      Robert Griesemer (Gerrit)

      unread,
      Sep 22, 2022, 4:49:00 PM9/22/22
      to Robert Griesemer, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

      Attention is currently required from: Robert Findley, Robert Griesemer, Robert Griesemer.

      Robert Griesemer uploaded patch set #5 to this change.

      View Change

      go/types, types2: use "and not used" instead of "but not used" in error messages

      This matches longstanding compiler behavior.

      Also, for unused packages, report:

      `"pkg" imported and not used`
      `"pkg" imported as X and not used`

      This matches the other `X declared and not used` errors.


      For #55326.

      Change-Id: Ie71cf662fb5f4648449c64fc51bede298a1bdcbf
      ---
      M src/cmd/compile/internal/types2/assignments.go
      M src/cmd/compile/internal/types2/errorcodes.go
      M src/cmd/compile/internal/types2/issues_test.go
      M src/cmd/compile/internal/types2/labels.go
      M src/cmd/compile/internal/types2/resolver.go
      M src/cmd/compile/internal/types2/stmt.go
      M src/go/types/assignments.go
      M src/go/types/errorcodes.go
      M src/go/types/issues_test.go
      M src/go/types/labels.go
      M src/go/types/resolver.go
      M src/go/types/stmt.go
      M src/internal/types/testdata/check/importdecl0/importdecl0a.go
      M src/internal/types/testdata/check/importdecl0/importdecl0b.go
      M src/internal/types/testdata/check/importdecl1/importdecl1b.go
      M src/internal/types/testdata/check/issues0.go
      M src/internal/types/testdata/check/labels.go
      M src/internal/types/testdata/check/stmt0.go
      M src/internal/types/testdata/check/vardecl.go
      M src/internal/types/testdata/fixedbugs/issue39634.go
      M src/internal/types/testdata/fixedbugs/issue43109.go
      M test/fixedbugs/bug373.go
      M test/fixedbugs/bug450.go
      M test/fixedbugs/issue13415.go
      M test/fixedbugs/issue13539.go
      M test/fixedbugs/issue18915.go
      M test/fixedbugs/issue20185.go
      M test/fixedbugs/issue21317.go
      M test/fixedbugs/issue22794.go
      M test/fixedbugs/issue23116.go
      M test/fixedbugs/issue23586.go
      M test/fixedbugs/issue29870b.go
      M test/fixedbugs/issue5957.dir/c.go
      M test/import1.go
      M test/import4.dir/import4.go
      M test/typeswitch2b.go
      36 files changed, 130 insertions(+), 118 deletions(-)

      To view, visit change 432557. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ie71cf662fb5f4648449c64fc51bede298a1bdcbf
      Gerrit-Change-Number: 432557
      Gerrit-PatchSet: 5
      Gerrit-Owner: Robert Griesemer <g...@golang.org>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      Gerrit-Reviewer: Robert Findley <rfin...@google.com>
      Gerrit-Reviewer: Robert Griesemer <g...@google.com>
      Gerrit-Attention: Robert Findley <rfin...@google.com>
      Gerrit-Attention: Robert Griesemer <g...@golang.org>
      Gerrit-Attention: Robert Griesemer <g...@google.com>
      Gerrit-MessageType: newpatchset

      Robert Griesemer (Gerrit)

      unread,
      Sep 22, 2022, 4:57:17 PM9/22/22
      to Robert Griesemer, goph...@pubsubhelper.golang.org, Robert Findley, Gopher Robot, golang-co...@googlegroups.com

      Attention is currently required from: Robert Findley, Robert Griesemer.

      Patch set 5:Run-TryBot +1Auto-Submit +1Code-Review +1

      View Change

        To view, visit change 432557. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: Ie71cf662fb5f4648449c64fc51bede298a1bdcbf
        Gerrit-Change-Number: 432557
        Gerrit-PatchSet: 5
        Gerrit-Owner: Robert Griesemer <g...@golang.org>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        Gerrit-Reviewer: Robert Findley <rfin...@google.com>
        Gerrit-Reviewer: Robert Griesemer <g...@google.com>
        Gerrit-Attention: Robert Findley <rfin...@google.com>
        Gerrit-Attention: Robert Griesemer <g...@golang.org>
        Gerrit-Comment-Date: Thu, 22 Sep 2022 20:57:11 +0000

        Robert Griesemer (Gerrit)

        unread,
        Sep 24, 2022, 1:27:14 PM9/24/22
        to Robert Griesemer, goph...@pubsubhelper.golang.org, Gopher Robot, Robert Findley, golang-co...@googlegroups.com

        Attention is currently required from: Robert Findley, Robert Griesemer.

        Patch set 8:Run-TryBot +1Auto-Submit +1Code-Review +1

        View Change

          To view, visit change 432557. To unsubscribe, or for help writing mail filters, visit settings.

          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: Ie71cf662fb5f4648449c64fc51bede298a1bdcbf
          Gerrit-Change-Number: 432557
          Gerrit-PatchSet: 8
          Gerrit-Owner: Robert Griesemer <g...@golang.org>
          Gerrit-Reviewer: Gopher Robot <go...@golang.org>
          Gerrit-Reviewer: Robert Findley <rfin...@google.com>
          Gerrit-Reviewer: Robert Griesemer <g...@google.com>
          Gerrit-Attention: Robert Findley <rfin...@google.com>
          Gerrit-Attention: Robert Griesemer <g...@golang.org>
          Gerrit-Comment-Date: Sat, 24 Sep 2022 17:27:09 +0000

          Robert Griesemer (Gerrit)

          unread,
          Sep 26, 2022, 7:55:18 PM9/26/22
          to Robert Griesemer, goph...@pubsubhelper.golang.org, Gopher Robot, Robert Findley, golang-co...@googlegroups.com

          Attention is currently required from: Robert Findley, Robert Griesemer.

          Patch set 10:Run-TryBot +1Auto-Submit +1Code-Review +1

          View Change

            To view, visit change 432557. To unsubscribe, or for help writing mail filters, visit settings.

            Gerrit-Project: go
            Gerrit-Branch: master
            Gerrit-Change-Id: Ie71cf662fb5f4648449c64fc51bede298a1bdcbf
            Gerrit-Change-Number: 432557
            Gerrit-PatchSet: 10
            Gerrit-Owner: Robert Griesemer <g...@golang.org>
            Gerrit-Reviewer: Gopher Robot <go...@golang.org>
            Gerrit-Reviewer: Robert Findley <rfin...@google.com>
            Gerrit-Reviewer: Robert Griesemer <g...@google.com>
            Gerrit-Attention: Robert Findley <rfin...@google.com>
            Gerrit-Attention: Robert Griesemer <g...@golang.org>
            Gerrit-Comment-Date: Mon, 26 Sep 2022 23:55:12 +0000

            Robert Findley (Gerrit)

            unread,
            Sep 27, 2022, 9:53:23 AM9/27/22
            to Robert Griesemer, goph...@pubsubhelper.golang.org, Gopher Robot, Robert Griesemer, golang-co...@googlegroups.com

            Attention is currently required from: Robert Griesemer, Robert Griesemer.

            Patch set 11:Run-TryBot +1Code-Review +2

            View Change

              To view, visit change 432557. To unsubscribe, or for help writing mail filters, visit settings.

              Gerrit-Project: go
              Gerrit-Branch: master
              Gerrit-Change-Id: Ie71cf662fb5f4648449c64fc51bede298a1bdcbf
              Gerrit-Change-Number: 432557
              Gerrit-PatchSet: 11
              Gerrit-Owner: Robert Griesemer <g...@golang.org>
              Gerrit-Reviewer: Gopher Robot <go...@golang.org>
              Gerrit-Reviewer: Robert Findley <rfin...@google.com>
              Gerrit-Reviewer: Robert Griesemer <g...@google.com>
              Gerrit-Attention: Robert Griesemer <g...@golang.org>
              Gerrit-Attention: Robert Griesemer <g...@google.com>
              Gerrit-Comment-Date: Tue, 27 Sep 2022 13:53:19 +0000

              Robert Findley (Gerrit)

              unread,
              Sep 27, 2022, 9:57:37 AM9/27/22
              to Robert Griesemer, goph...@pubsubhelper.golang.org, Gopher Robot, Robert Griesemer, golang-co...@googlegroups.com

              Attention is currently required from: Robert Griesemer, Robert Griesemer.

              View Change

              1 comment:

              • Patchset:

                • Patch Set #11:

                  Just saw that x/tools tests failed with this change. I'll fix.

              To view, visit change 432557. To unsubscribe, or for help writing mail filters, visit settings.

              Gerrit-Project: go
              Gerrit-Branch: master
              Gerrit-Change-Id: Ie71cf662fb5f4648449c64fc51bede298a1bdcbf
              Gerrit-Change-Number: 432557
              Gerrit-PatchSet: 11
              Gerrit-Owner: Robert Griesemer <g...@golang.org>
              Gerrit-Reviewer: Gopher Robot <go...@golang.org>
              Gerrit-Reviewer: Robert Findley <rfin...@google.com>
              Gerrit-Reviewer: Robert Griesemer <g...@google.com>
              Gerrit-Attention: Robert Griesemer <g...@golang.org>
              Gerrit-Attention: Robert Griesemer <g...@google.com>
              Gerrit-Comment-Date: Tue, 27 Sep 2022 13:57:33 +0000
              Gerrit-HasComments: Yes
              Gerrit-Has-Labels: No
              Gerrit-MessageType: comment

              Robert Griesemer (Gerrit)

              unread,
              Sep 27, 2022, 12:07:01 PM9/27/22
              to Robert Griesemer, goph...@pubsubhelper.golang.org, Gopher Robot, Robert Findley, golang-co...@googlegroups.com

              Attention is currently required from: Robert Griesemer.

              Patch set 11:Run-TryBot +1Auto-Submit +1Code-Review +1

              View Change

                To view, visit change 432557. To unsubscribe, or for help writing mail filters, visit settings.

                Gerrit-Project: go
                Gerrit-Branch: master
                Gerrit-Change-Id: Ie71cf662fb5f4648449c64fc51bede298a1bdcbf
                Gerrit-Change-Number: 432557
                Gerrit-PatchSet: 11
                Gerrit-Owner: Robert Griesemer <g...@golang.org>
                Gerrit-Reviewer: Gopher Robot <go...@golang.org>
                Gerrit-Reviewer: Robert Findley <rfin...@google.com>
                Gerrit-Reviewer: Robert Griesemer <g...@google.com>
                Gerrit-Attention: Robert Griesemer <g...@golang.org>
                Gerrit-Comment-Date: Tue, 27 Sep 2022 16:06:56 +0000

                Robert Griesemer (Gerrit)

                unread,
                Sep 27, 2022, 12:42:54 PM9/27/22
                to Robert Griesemer, goph...@pubsubhelper.golang.org, Gopher Robot, Robert Findley, golang-co...@googlegroups.com

                Attention is currently required from: Robert Findley, Robert Griesemer.

                Patch set 12:Run-TryBot +1Auto-Submit +1Code-Review +1

                View Change

                  To view, visit change 432557. To unsubscribe, or for help writing mail filters, visit settings.

                  Gerrit-Project: go
                  Gerrit-Branch: master
                  Gerrit-Change-Id: Ie71cf662fb5f4648449c64fc51bede298a1bdcbf
                  Gerrit-Change-Number: 432557
                  Gerrit-PatchSet: 12
                  Gerrit-Owner: Robert Griesemer <g...@golang.org>
                  Gerrit-Reviewer: Gopher Robot <go...@golang.org>
                  Gerrit-Reviewer: Robert Findley <rfin...@google.com>
                  Gerrit-Reviewer: Robert Griesemer <g...@google.com>
                  Gerrit-Attention: Robert Findley <rfin...@google.com>
                  Gerrit-Attention: Robert Griesemer <g...@golang.org>
                  Gerrit-Comment-Date: Tue, 27 Sep 2022 16:42:48 +0000

                  Robert Findley (Gerrit)

                  unread,
                  Sep 27, 2022, 4:30:25 PM9/27/22
                  to Robert Griesemer, goph...@pubsubhelper.golang.org, Gopher Robot, Robert Griesemer, golang-co...@googlegroups.com

                  Attention is currently required from: Robert Findley, Robert Griesemer.

                  Robert Findley removed a vote from this change.

                  View Change

                  Removed TryBot-Result-1 by Gopher Robot <go...@golang.org>

                  To view, visit change 432557. To unsubscribe, or for help writing mail filters, visit settings.

                  Gerrit-Project: go
                  Gerrit-Branch: master
                  Gerrit-Change-Id: Ie71cf662fb5f4648449c64fc51bede298a1bdcbf
                  Gerrit-Change-Number: 432557
                  Gerrit-PatchSet: 12
                  Gerrit-Owner: Robert Griesemer <g...@golang.org>
                  Gerrit-Reviewer: Gopher Robot <go...@golang.org>
                  Gerrit-Reviewer: Robert Findley <rfin...@google.com>
                  Gerrit-Reviewer: Robert Griesemer <g...@google.com>
                  Gerrit-Attention: Robert Findley <rfin...@google.com>
                  Gerrit-Attention: Robert Griesemer <g...@golang.org>
                  Gerrit-MessageType: deleteVote

                  Gopher Robot (Gerrit)

                  unread,
                  Sep 27, 2022, 5:10:24 PM9/27/22
                  to Robert Griesemer, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Robert Griesemer, Robert Findley, golang-co...@googlegroups.com

                  Gopher Robot submitted this change.

                  View Change



                  11 is the latest approved patch-set.
                  No files were changed between the latest approved patch-set and the submitted one.

                  Approvals: Robert Findley: Looks good to me, approved Robert Griesemer: Looks good to me, but someone else must approve; Run TryBots; Automatically submit change Gopher Robot: TryBots succeeded
                  go/types, types2: use "and not used" instead of "but not used" in error messages

                  This matches longstanding compiler behavior.

                  Also, for unused packages, report:

                  `"pkg" imported and not used`
                  `"pkg" imported as X and not used`

                  This matches the other `X declared and not used` errors.

                  For #55326.

                  Change-Id: Ie71cf662fb5f4648449c64fc51bede298a1bdcbf
                  Reviewed-on: https://go-review.googlesource.com/c/go/+/432557
                  TryBot-Result: Gopher Robot <go...@golang.org>
                  Reviewed-by: Robert Findley <rfin...@google.com>
                  Reviewed-by: Robert Griesemer <g...@google.com>
                  Auto-Submit: Robert Griesemer <g...@google.com>
                  Run-TryBot: Robert Griesemer <g...@google.com>
                  36 files changed, 136 insertions(+), 118 deletions(-)

                  diff --git a/src/cmd/compile/internal/types2/assignments.go b/src/cmd/compile/internal/types2/assignments.go
                  index 1396284..10e3575 100644
                  --- a/src/cmd/compile/internal/types2/assignments.go
                  +++ b/src/cmd/compile/internal/types2/assignments.go
                  @@ -142,7 +142,7 @@
                  }
                  // Note: This was reverted in go/types (https://golang.org/cl/292751).
                  // TODO(gri): decide what to do (also affects test/run.go exclusion list)
                  - lhs.used = true // avoid follow-on "declared but not used" errors
                  + lhs.used = true // avoid follow-on "declared and not used" errors
                  return nil
                  }

                  @@ -163,7 +163,7 @@

                  check.assignment(x, lhs.typ, context)
                  if x.mode == invalid {
                  - lhs.used = true // avoid follow-on "declared but not used" errors
                  + lhs.used = true // avoid follow-on "declared and not used" errors
                  return nil
                  }

                  @@ -325,7 +325,7 @@
                  if len(lhs) != len(rhs) {
                  // invalidate lhs
                  for _, obj := range lhs {
                  - obj.used = true // avoid declared but not used errors
                  + obj.used = true // avoid declared and not used errors
                  if obj.typ == nil {
                  obj.typ = Typ[Invalid]
                  }
                  @@ -382,7 +382,7 @@
                  }
                  }

                  - // avoid follow-on "declared but not used" errors if any initialization failed
                  + // avoid follow-on "declared and not used" errors if any initialization failed
                  if !ok {
                  for _, lhs := range lhs {
                  lhs.used = true
                  @@ -425,7 +425,7 @@
                  }
                  }

                  - // avoid follow-on "declared but not used" errors if any assignment failed
                  + // avoid follow-on "declared and not used" errors if any assignment failed
                  if !ok {
                  // don't call check.use to avoid re-evaluation of the lhs expressions
                  for _, lhs := range lhs {
                  diff --git a/src/cmd/compile/internal/types2/errorcodes.go b/src/cmd/compile/internal/types2/errorcodes.go
                  index 6b3e6d6..f243889 100644
                  --- a/src/cmd/compile/internal/types2/errorcodes.go
                  +++ b/src/cmd/compile/internal/types2/errorcodes.go
                  @@ -1154,7 +1154,7 @@
                  // }
                  _MisplacedLabel

                  - // _UnusedLabel occurs when a label is declared but not used.
                  + // _UnusedLabel occurs when a label is declared and not used.
                  //
                  // Example:
                  // func f() {
                  diff --git a/src/cmd/compile/internal/types2/issues_test.go b/src/cmd/compile/internal/types2/issues_test.go
                  index 78691b9..efd27bf 100644
                  --- a/src/cmd/compile/internal/types2/issues_test.go
                  +++ b/src/cmd/compile/internal/types2/issues_test.go
                  @@ -285,11 +285,11 @@
                  conf := Config{Error: func(err error) { got += err.Error() + "\n" }}
                  conf.Check(f.PkgName.Value, []*syntax.File{f}, nil) // do not crash
                  want := `
                  -:1:27: a declared but not used
                  -:1:30: b declared but not used
                  -:1:33: c declared but not used
                  -:1:36: d declared but not used
                  -:1:39: e declared but not used
                  +:1:27: a declared and not used
                  +:1:30: b declared and not used
                  +:1:33: c declared and not used
                  +:1:36: d declared and not used
                  +:1:39: e declared and not used
                  `
                  if got != want {
                  t.Errorf("got: %swant: %s", got, want)
                  diff --git a/src/cmd/compile/internal/types2/labels.go b/src/cmd/compile/internal/types2/labels.go
                  index 24349e3..9163a58 100644
                  --- a/src/cmd/compile/internal/types2/labels.go
                  +++ b/src/cmd/compile/internal/types2/labels.go
                  @@ -38,7 +38,7 @@
                  for name, obj := range all.elems {
                  obj = resolve(name, obj)
                  if lbl := obj.(*Label); !lbl.used {
                  - check.softErrorf(lbl.pos, _UnusedLabel, "label %s declared but not used", lbl.name)
                  + check.softErrorf(lbl.pos, _UnusedLabel, "label %s declared and not used", lbl.name)
                  }
                  }
                  }
                  diff --git a/src/cmd/compile/internal/types2/resolver.go b/src/cmd/compile/internal/types2/resolver.go
                  index ac89124..f9aa3ad 100644
                  --- a/src/cmd/compile/internal/types2/resolver.go
                  +++ b/src/cmd/compile/internal/types2/resolver.go
                  @@ -727,17 +727,9 @@

                  elem = elem[i+1:]
                  }
                  if obj.name == "" || obj.name == "." || obj.name == elem {
                  - if check.conf.CompilerErrorMessages {
                  - check.softErrorf(obj, _UnusedImport, "imported and not used: %q", path)
                  - } else {
                  - check.softErrorf(obj, _UnusedImport, "%q imported but not used", path)
                  - }
                  +		check.softErrorf(obj, _UnusedImport, "%q imported and not used", path)

                  } else {
                  - if check.conf.CompilerErrorMessages {
                  - check.softErrorf(obj, _UnusedImport, "imported and not used: %q as %s", path, obj.name)
                  - } else {
                  - check.softErrorf(obj, _UnusedImport, "%q imported but not used as %s", path, obj.name)
                  - }
                  +		check.softErrorf(obj, _UnusedImport, "%q imported as %s and not used", path, obj.name)
                  }
                  }

                  diff --git a/src/cmd/compile/internal/types2/stmt.go b/src/cmd/compile/internal/types2/stmt.go
                  index 6502315..3ff80e8 100644
                  --- a/src/cmd/compile/internal/types2/stmt.go
                  +++ b/src/cmd/compile/internal/types2/stmt.go
                  @@ -66,7 +66,7 @@
                  return unused[i].pos.Cmp(unused[j].pos) < 0
                  })
                  for _, v := range unused {
                  - check.softErrorf(v.pos, _UnusedVar, "%s declared but not used", v.name)
                  + check.softErrorf(v.pos, _UnusedVar, "%s declared and not used", v.name)
                  }

                  for _, scope := range scope.children {
                  @@ -741,7 +741,7 @@
                  if lhs.Value == "_" {
                  // _ := x.(type) is an invalid short variable declaration
                  check.softErrorf(lhs, _NoNewVar, "no new variable on left side of :=")
                  - lhs = nil // avoid declared but not used error below
                  + lhs = nil // avoid declared and not used error below
                  } else {
                  check.recordDef(lhs, nil) // lhs variable is implicitly declared in each cause clause
                  }
                  @@ -802,7 +802,7 @@
                  }
                  check.declare(check.scope, nil, obj, scopePos)
                  check.recordImplicit(clause, obj)
                  - // For the "declared but not used" error, all lhs variables act as
                  + // For the "declared and not used" error, all lhs variables act as
                  // one; i.e., if any one of them is 'used', all of them are 'used'.
                  // Collect them for later analysis.
                  lhsVars = append(lhsVars, obj)
                  @@ -824,7 +824,7 @@
                  v.used = true // avoid usage error when checking entire function
                  }
                  if !used {
                  - check.softErrorf(lhs, _UnusedVar, "%s declared but not used", lhs.Value)
                  + check.softErrorf(lhs, _UnusedVar, "%s declared and not used", lhs.Value)
                  }
                  }
                  }
                  diff --git a/src/go/types/assignments.go b/src/go/types/assignments.go
                  index 98d7563..89b3e1b 100644
                  --- a/src/go/types/assignments.go
                  +++ b/src/go/types/assignments.go
                  @@ -320,7 +320,7 @@
                  if len(lhs) != len(rhs) {
                  // invalidate lhs
                  for _, obj := range lhs {
                  - obj.used = true // avoid declared but not used errors
                  + obj.used = true // avoid declared and not used errors
                  if obj.typ == nil {
                  obj.typ = Typ[Invalid]
                  }
                  diff --git a/src/go/types/errorcodes.go b/src/go/types/errorcodes.go
                  index 3c224a1..7b5548b 100644
                  --- a/src/go/types/errorcodes.go
                  +++ b/src/go/types/errorcodes.go
                  @@ -1154,7 +1154,7 @@
                  // }
                  _MisplacedLabel

                  - // _UnusedLabel occurs when a label is declared but not used.
                  + // _UnusedLabel occurs when a label is declared and not used.
                  //
                  // Example:
                  // func f() {
                  diff --git a/src/go/types/issues_test.go b/src/go/types/issues_test.go
                  index b033460..85362fb 100644
                  --- a/src/go/types/issues_test.go
                  +++ b/src/go/types/issues_test.go
                  @@ -288,11 +288,11 @@
                  conf := Config{Error: func(err error) { got += err.Error() + "\n" }}
                  conf.Check(f.Name.Name, fset, []*ast.File{f}, nil) // do not crash
                  want := `
                  -1:27: a declared but not used
                  -1:30: b declared but not used
                  -1:33: c declared but not used
                  -1:36: d declared but not used
                  -1:39: e declared but not used
                  +1:27: a declared and not used
                  +1:30: b declared and not used
                  +1:33: c declared and not used
                  +1:36: d declared and not used
                  +1:39: e declared and not used
                  `
                  if got != want {
                  t.Errorf("got: %swant: %s", got, want)
                  diff --git a/src/go/types/labels.go b/src/go/types/labels.go
                  index f3b7f21..46055cb 100644
                  --- a/src/go/types/labels.go
                  +++ b/src/go/types/labels.go
                  @@ -39,7 +39,7 @@
                  for name, obj := range all.elems {
                  obj = resolve(name, obj)
                  if lbl := obj.(*Label); !lbl.used {
                  - check.softErrorf(lbl, _UnusedLabel, "label %s declared but not used", lbl.name)
                  + check.softErrorf(lbl, _UnusedLabel, "label %s declared and not used", lbl.name)
                  }
                  }
                  }
                  diff --git a/src/go/types/resolver.go b/src/go/types/resolver.go
                  index 12ec55a..b09083b 100644
                  --- a/src/go/types/resolver.go
                  +++ b/src/go/types/resolver.go
                  @@ -69,11 +69,11 @@
                  // init exprs from s
                  n := s.Values[l]
                  check.errorf(n, code, "extra init expr %s", n)
                  - // TODO(gri) avoid declared but not used error here
                  + // TODO(gri) avoid declared and not used error here
                  } else {
                  // init exprs "inherited"
                  check.errorf(s, code, "extra init expr at %s", check.fset.Position(init.Pos()))
                  - // TODO(gri) avoid declared but not used error here
                  + // TODO(gri) avoid declared and not used error here
                  }
                  case l > r && (init != nil || r != 1):
                  n := s.Names[r]
                  @@ -706,9 +706,9 @@

                  elem = elem[i+1:]
                  }
                  if obj.name == "" || obj.name == "." || obj.name == elem {
                  -		check.softErrorf(obj, _UnusedImport, "%q imported but not used", path)
                  +		check.softErrorf(obj, _UnusedImport, "%q imported and not used", path)

                  } else {
                  - check.softErrorf(obj, _UnusedImport, "%q imported but not used as %s", path, obj.name)
                  +		check.softErrorf(obj, _UnusedImport, "%q imported as %s and not used", path, obj.name)
                  }
                  }

                  diff --git a/src/go/types/stmt.go b/src/go/types/stmt.go
                  index 9bfc1cd..30e9480 100644
                  --- a/src/go/types/stmt.go
                  +++ b/src/go/types/stmt.go
                  @@ -67,7 +67,7 @@
                  return unused[i].pos < unused[j].pos
                  })
                  for _, v := range unused {
                  - check.softErrorf(v, _UnusedVar, "%s declared but not used", v.name)
                  + check.softErrorf(v, _UnusedVar, "%s declared and not used", v.name)
                  }

                  for _, scope := range scope.children {
                  @@ -666,7 +666,7 @@
                  if lhs.Name == "_" {
                  // _ := x.(type) is an invalid short variable declaration
                  check.softErrorf(lhs, _NoNewVar, "no new variable on left side of :=")
                  - lhs = nil // avoid declared but not used error below
                  + lhs = nil // avoid declared and not used error below
                  } else {
                  check.recordDef(lhs, nil) // lhs variable is implicitly declared in each cause clause
                  }
                  @@ -731,7 +731,7 @@
                  }
                  check.declare(check.scope, nil, obj, scopePos)
                  check.recordImplicit(clause, obj)
                  - // For the "declared but not used" error, all lhs variables act as
                  + // For the "declared and not used" error, all lhs variables act as
                  // one; i.e., if any one of them is 'used', all of them are 'used'.
                  // Collect them for later analysis.
                  lhsVars = append(lhsVars, obj)
                  @@ -750,7 +750,7 @@
                  v.used = true // avoid usage error when checking entire function
                  }
                  if !used {
                  - check.softErrorf(lhs, _UnusedVar, "%s declared but not used", lhs.Name)
                  + check.softErrorf(lhs, _UnusedVar, "%s declared and not used", lhs.Name)
                  }
                  }

                  @@ -819,7 +819,7 @@
                  check.softErrorf(s, _InvalidPostDecl, "cannot declare in post statement")
                  // Don't call useLHS here because we want to use the lhs in
                  // this erroneous statement so that we don't get errors about
                  - // these lhs variables being declared but not used.
                  + // these lhs variables being declared and not used.
                  check.use(s.Lhs...) // avoid follow-up errors
                  }
                  check.stmt(inner, s.Body)
                  diff --git a/src/internal/types/testdata/check/importdecl0/importdecl0a.go b/src/internal/types/testdata/check/importdecl0/importdecl0a.go
                  index 5ceb96e..d514ae4 100644
                  --- a/src/internal/types/testdata/check/importdecl0/importdecl0a.go
                  +++ b/src/internal/types/testdata/check/importdecl0/importdecl0a.go
                  @@ -13,16 +13,16 @@
                  init /* ERROR "cannot import package as init" */ "fmt"
                  // reflect defines a type "flag" which shows up in the gc export data
                  "reflect"
                  - . /* ERROR "imported but not used" */ "reflect"
                  + . /* ERROR "imported and not used" */ "reflect"
                  )

                  -import "math" /* ERROR "imported but not used" */

                  -import m /* ERROR "imported but not used as m" */ "math"
                  +import "math" /* ERROR "imported and not used" */
                  +import m /* ERROR "imported as m and not used" */ "math"

                  import _ "math"

                  import (
                  -	"math/big" /* ERROR "imported but not used" */

                  - b /* ERROR "imported but not used" */ "math/big"
                  +	"math/big" /* ERROR "imported and not used" */
                  + b /* ERROR "imported as b and not used" */ "math/big"
                  _ "math/big"
                  )

                  diff --git a/src/internal/types/testdata/check/importdecl0/importdecl0b.go b/src/internal/types/testdata/check/importdecl0/importdecl0b.go
                  index 19b55af..904faff 100644
                  --- a/src/internal/types/testdata/check/importdecl0/importdecl0b.go
                  +++ b/src/internal/types/testdata/check/importdecl0/importdecl0b.go
                  @@ -8,7 +8,7 @@
                  import m "math"

                  import . "testing" // declares T in file scope
                  -import . /* ERROR .unsafe. imported but not used */ "unsafe"
                  +import . /* ERROR .unsafe. imported and not used */ "unsafe"
                  import . "fmt" // declares Println in file scope

                  import (
                  diff --git a/src/internal/types/testdata/check/importdecl1/importdecl1b.go b/src/internal/types/testdata/check/importdecl1/importdecl1b.go
                  index 43a7bcd..ce8b983 100644
                  --- a/src/internal/types/testdata/check/importdecl1/importdecl1b.go
                  +++ b/src/internal/types/testdata/check/importdecl1/importdecl1b.go
                  @@ -4,7 +4,7 @@

                  package importdecl1

                  -import . /* ERROR .unsafe. imported but not used */ "unsafe"
                  +import . /* ERROR .unsafe. imported and not used */ "unsafe"

                  type B interface {
                  A
                  diff --git a/src/internal/types/testdata/check/issues0.go b/src/internal/types/testdata/check/issues0.go
                  index fc0c028..5f46021 100644
                  --- a/src/internal/types/testdata/check/issues0.go
                  +++ b/src/internal/types/testdata/check/issues0.go
                  @@ -204,7 +204,7 @@
                  _ = v
                  }

                  -// Test that we don't get "declared but not used"
                  +// Test that we don't get "declared and not used"
                  // errors in the context of invalid/C objects.
                  func issue20358() {
                  var F C /* ERROR "undefined" */ .F
                  diff --git a/src/internal/types/testdata/check/labels.go b/src/internal/types/testdata/check/labels.go
                  index 9f42406..5948952 100644
                  --- a/src/internal/types/testdata/check/labels.go
                  +++ b/src/internal/types/testdata/check/labels.go
                  @@ -10,19 +10,19 @@
                  var x int

                  func f0() {
                  -L1 /* ERROR "label L1 declared but not used" */ :
                  +L1 /* ERROR "label L1 declared and not used" */ :
                  for {
                  }
                  -L2 /* ERROR "label L2 declared but not used" */ :
                  +L2 /* ERROR "label L2 declared and not used" */ :
                  select {
                  }
                  -L3 /* ERROR "label L3 declared but not used" */ :
                  +L3 /* ERROR "label L3 declared and not used" */ :
                  switch {
                  }
                  -L4 /* ERROR "label L4 declared but not used" */ :
                  +L4 /* ERROR "label L4 declared and not used" */ :
                  if true {
                  }
                  -L5 /* ERROR "label L5 declared but not used" */ :
                  +L5 /* ERROR "label L5 declared and not used" */ :
                  f0()
                  L6:
                  f0()
                  @@ -41,7 +41,7 @@
                  // A label must be directly associated with a switch, select, or
                  // for statement; it cannot be the label of a labeled statement.

                  -L7a /* ERROR "declared but not used" */ : L7b:
                  +L7a /* ERROR "declared and not used" */ : L7b:
                  for {
                  break L7a /* ERROR "invalid break label L7a" */
                  continue L7a /* ERROR "invalid continue label L7a" */
                  @@ -60,7 +60,7 @@
                  switch {
                  case true:
                  break L9
                  - defalt /* ERROR "label defalt declared but not used" */ :
                  + defalt /* ERROR "label defalt declared and not used" */ :
                  }

                  L10:
                  @@ -157,7 +157,7 @@
                  // Additional tests not in the original files.

                  func f2() {
                  -L1 /* ERROR "label L1 declared but not used" */ :
                  +L1 /* ERROR "label L1 declared and not used" */ :
                  if x == 0 {
                  for {
                  continue L1 /* ERROR "invalid continue label L1" */
                  diff --git a/src/internal/types/testdata/check/stmt0.go b/src/internal/types/testdata/check/stmt0.go
                  index 799f5e7..3dc5681 100644
                  --- a/src/internal/types/testdata/check/stmt0.go
                  +++ b/src/internal/types/testdata/check/stmt0.go
                  @@ -222,7 +222,7 @@
                  ch2 := make(chan int)
                  select {
                  case <-ch1:
                  - var ch2 /* ERROR ch2 declared but not used */ chan bool
                  + var ch2 /* ERROR ch2 declared and not used */ chan bool
                  case i := <-ch2:
                  print(i + 1)
                  }
                  @@ -688,7 +688,7 @@
                  default /* ERROR "multiple defaults" */ :
                  }

                  - switch x /* ERROR "declared but not used" */ := x.(type) {}
                  + switch x /* ERROR "declared and not used" */ := x.(type) {}
                  switch _ /* ERROR "no new variable on left side of :=" */ := x.(type) {}

                  switch x := x.(type) {
                  @@ -697,7 +697,7 @@
                  _ = y
                  }

                  - switch x /* ERROR "x declared but not used" */ := i /* ERROR "not an interface" */ .(type) {}
                  + switch x /* ERROR "x declared and not used" */ := i /* ERROR "not an interface" */ .(type) {}

                  switch t := x.(type) {
                  case nil:
                  @@ -950,7 +950,7 @@
                  // the loop body is still type-checked (and thus
                  // errors reported).
                  func issue10148() {
                  - for y /* ERROR declared but not used */ := range "" {
                  + for y /* ERROR declared and not used */ := range "" {
                  _ = "" /* ERROR mismatched types untyped string and untyped int */ + 1
                  }
                  for range 1 /* ERROR cannot range over 1 */ {
                  diff --git a/src/internal/types/testdata/check/vardecl.go b/src/internal/types/testdata/check/vardecl.go
                  index 6f059fe..6b6a45b 100644
                  --- a/src/internal/types/testdata/check/vardecl.go
                  +++ b/src/internal/types/testdata/check/vardecl.go
                  @@ -64,45 +64,45 @@
                  // Variables declared in function bodies must be 'used'.
                  type T struct{}
                  func (r T) _(a, b, c int) (u, v, w int) {
                  - var x1 /* ERROR "declared but not used" */ int
                  - var x2 /* ERROR "declared but not used" */ int
                  + var x1 /* ERROR "declared and not used" */ int
                  + var x2 /* ERROR "declared and not used" */ int
                  x1 = 1
                  (x2) = 2

                  - y1 /* ERROR "declared but not used" */ := 1
                  - y2 /* ERROR "declared but not used" */ := 2
                  + y1 /* ERROR "declared and not used" */ := 1
                  + y2 /* ERROR "declared and not used" */ := 2
                  y1 = 1
                  (y1) = 2

                  {
                  - var x1 /* ERROR "declared but not used" */ int
                  - var x2 /* ERROR "declared but not used" */ int
                  + var x1 /* ERROR "declared and not used" */ int
                  + var x2 /* ERROR "declared and not used" */ int
                  x1 = 1
                  (x2) = 2

                  - y1 /* ERROR "declared but not used" */ := 1
                  - y2 /* ERROR "declared but not used" */ := 2
                  + y1 /* ERROR "declared and not used" */ := 1
                  + y2 /* ERROR "declared and not used" */ := 2
                  y1 = 1
                  (y1) = 2
                  }

                  - if x /* ERROR "declared but not used" */ := 0; a < b {}
                  + if x /* ERROR "declared and not used" */ := 0; a < b {}

                  - switch x /* ERROR "declared but not used" */, y := 0, 1; a {
                  + switch x /* ERROR "declared and not used" */, y := 0, 1; a {
                  case 0:
                  _ = y
                  case 1:
                  - x /* ERROR "declared but not used" */ := 0
                  + x /* ERROR "declared and not used" */ := 0
                  }

                  var t interface{}
                  - switch t /* ERROR "declared but not used" */ := t.(type) {}
                  + switch t /* ERROR "declared and not used" */ := t.(type) {}

                  - switch t /* ERROR "declared but not used" */ := t.(type) {
                  + switch t /* ERROR "declared and not used" */ := t.(type) {
                  case int:
                  }

                  - switch t /* ERROR "declared but not used" */ := t.(type) {
                  + switch t /* ERROR "declared and not used" */ := t.(type) {
                  case int:
                  case float32, complex64:
                  t = nil
                  @@ -123,9 +123,9 @@
                  }
                  }

                  - switch t := t; t /* ERROR "declared but not used" */ := t.(type) {}
                  + switch t := t; t /* ERROR "declared and not used" */ := t.(type) {}

                  - var z1 /* ERROR "declared but not used" */ int
                  + var z1 /* ERROR "declared and not used" */ int
                  var z2 int
                  _ = func(a, b, c int) (u, v, w int) {
                  z1 = a
                  @@ -135,12 +135,12 @@
                  }

                  var s []int
                  - var i /* ERROR "declared but not used" */ , j int
                  + var i /* ERROR "declared and not used" */ , j int
                  for i, j = range s {
                  _ = j
                  }

                  - for i, j /* ERROR "declared but not used" */ := range s {
                  + for i, j /* ERROR "declared and not used" */ := range s {
                  _ = func() int {
                  return i
                  }
                  @@ -151,12 +151,12 @@
                  // Unused variables in function literals must lead to only one error (issue #22524).
                  func _() {
                  _ = func() {
                  - var x /* ERROR declared but not used */ int
                  + var x /* ERROR declared and not used */ int
                  }
                  }

                  -// Invalid variable declarations must not lead to "declared but not used errors".
                  -// TODO(gri) enable these tests once go/types follows types2 logic for declared but not used variables
                  +// Invalid variable declarations must not lead to "declared and not used errors".
                  +// TODO(gri) enable these tests once go/types follows types2 logic for declared and not used variables
                  // func _() {
                  // var a x // DISABLED_ERROR undefined: x
                  // var b = x // DISABLED_ERROR undefined: x
                  @@ -164,10 +164,10 @@
                  // var d, e, f x /* DISABLED_ERROR x */ /* DISABLED_ERROR x */ /* DISABLED_ERROR x */
                  // var g, h, i = x, x, x /* DISABLED_ERROR x */ /* DISABLED_ERROR x */ /* DISABLED_ERROR x */
                  // var j, k, l float32 = x, x, x /* DISABLED_ERROR x */ /* DISABLED_ERROR x */ /* DISABLED_ERROR x */
                  -// // but no "declared but not used" errors
                  +// // but no "declared and not used" errors
                  // }

                  -// Invalid (unused) expressions must not lead to spurious "declared but not used errors".
                  +// Invalid (unused) expressions must not lead to spurious "declared and not used errors".
                  func _() {
                  var a, b, c int
                  var x, y int
                  diff --git a/src/internal/types/testdata/fixedbugs/issue39634.go b/src/internal/types/testdata/fixedbugs/issue39634.go
                  index f89fe37..7b458f2 100644
                  --- a/src/internal/types/testdata/fixedbugs/issue39634.go
                  +++ b/src/internal/types/testdata/fixedbugs/issue39634.go
                  @@ -42,7 +42,7 @@
                  var u /* ERROR cycle */ , i [func /* ERROR used as value */ /* ERROR used as value */ (u, c /* ERROR undefined */ /* ERROR undefined */ ) {}(0, len /* ERROR must be called */ /* ERROR must be called */ )]c /* ERROR undefined */ /* ERROR undefined */

                  // crash 15
                  -func y15() { var a /* ERROR declared but not used */ interface{ p() } = G15[string]{} }
                  +func y15() { var a /* ERROR declared and not used */ interface{ p() } = G15[string]{} }
                  type G15[X any] s /* ERROR undefined */
                  func (G15 /* ERROR generic type .* without instantiation */ ) p()

                  diff --git a/src/internal/types/testdata/fixedbugs/issue43109.go b/src/internal/types/testdata/fixedbugs/issue43109.go
                  index a4533c9..f242f16 100644
                  --- a/src/internal/types/testdata/fixedbugs/issue43109.go
                  +++ b/src/internal/types/testdata/fixedbugs/issue43109.go
                  @@ -2,7 +2,7 @@
                  // Use of this source code is governed by a BSD-style
                  // license that can be found in the LICENSE file.

                  -// Ensure there is no "imported but not used" error
                  +// Ensure there is no "imported and not used" error
                  // if a package wasn't imported in the first place.

                  package p
                  diff --git a/test/fixedbugs/bug373.go b/test/fixedbugs/bug373.go
                  index 6b7a312..aa0f5d1 100644
                  --- a/test/fixedbugs/bug373.go
                  +++ b/test/fixedbugs/bug373.go
                  @@ -9,7 +9,7 @@
                  package foo

                  func f(x interface{}) {
                  - switch t := x.(type) { // ERROR "declared but not used"
                  + switch t := x.(type) { // ERROR "declared and not used"
                  case int:
                  }
                  }
                  diff --git a/test/fixedbugs/bug450.go b/test/fixedbugs/bug450.go
                  index af27b72..f64063a 100644
                  --- a/test/fixedbugs/bug450.go
                  +++ b/test/fixedbugs/bug450.go
                  @@ -5,7 +5,7 @@
                  // license that can be found in the LICENSE file.

                  // Issue 3899: 8g incorrectly thinks a variable is
                  -// "set but not used" and elides an assignment, causing
                  +// "set and not used" and elides an assignment, causing
                  // variables to end up with wrong data.
                  //
                  // The reason is a miscalculation of variable width.
                  diff --git a/test/fixedbugs/issue13415.go b/test/fixedbugs/issue13415.go
                  index 4c4655e..cc17b84 100644
                  --- a/test/fixedbugs/issue13415.go
                  +++ b/test/fixedbugs/issue13415.go
                  @@ -11,7 +11,7 @@

                  func f() {
                  select {
                  - case x, x := <-func() chan int { // ERROR "x repeated on left side of :=|redefinition|declared but not used"
                  + case x, x := <-func() chan int { // ERROR "x repeated on left side of :=|redefinition|declared and not used"
                  c := make(chan int)
                  return c
                  }():
                  diff --git a/test/fixedbugs/issue13539.go b/test/fixedbugs/issue13539.go
                  index 181fbef..72c3ab0 100644
                  --- a/test/fixedbugs/issue13539.go
                  +++ b/test/fixedbugs/issue13539.go
                  @@ -10,7 +10,7 @@

                  package main

                  -import "math" // ERROR "imported and not used|imported but not used"
                  +import "math" // ERROR "imported and not used"

                  func main() {
                  math:
                  diff --git a/test/fixedbugs/issue18915.go b/test/fixedbugs/issue18915.go
                  index 22f97c6..cf248b1 100644
                  --- a/test/fixedbugs/issue18915.go
                  +++ b/test/fixedbugs/issue18915.go
                  @@ -10,12 +10,12 @@
                  package p

                  func _() {
                  - if a := 10 { // ERROR "cannot use a := 10 as value|expected .*;|declared but not used"
                  + if a := 10 { // ERROR "cannot use a := 10 as value|expected .*;|declared and not used"
                  }

                  - for b := 10 { // ERROR "cannot use b := 10 as value|parse error|declared but not used"
                  + for b := 10 { // ERROR "cannot use b := 10 as value|parse error|declared and not used"
                  }

                  - switch c := 10 { // ERROR "cannot use c := 10 as value|expected .*;|declared but not used"
                  + switch c := 10 { // ERROR "cannot use c := 10 as value|expected .*;|declared and not used"
                  }
                  }
                  diff --git a/test/fixedbugs/issue20185.go b/test/fixedbugs/issue20185.go
                  index ee60cab..3f79b75 100644
                  --- a/test/fixedbugs/issue20185.go
                  +++ b/test/fixedbugs/issue20185.go
                  @@ -19,7 +19,7 @@
                  const x = 1

                  func G() {
                  - switch t := x.(type) { // ERROR "cannot type switch on non-interface value|declared but not used|not an interface"
                  + switch t := x.(type) { // ERROR "cannot type switch on non-interface value|declared and not used|not an interface"
                  default:
                  }
                  }
                  diff --git a/test/fixedbugs/issue21317.go b/test/fixedbugs/issue21317.go
                  index fe51ef1..80797f7 100644
                  --- a/test/fixedbugs/issue21317.go
                  +++ b/test/fixedbugs/issue21317.go
                  @@ -44,8 +44,8 @@
                  log.Fatalf("expected cmd/compile to fail")
                  }
                  wantErrs := []string{
                  - "7:9: n declared but not used",
                  - "7:12: err declared but not used",
                  + "7:9: n declared and not used",
                  + "7:12: err declared and not used",
                  }
                  outStr := string(out)
                  for _, want := range wantErrs {
                  diff --git a/test/fixedbugs/issue22794.go b/test/fixedbugs/issue22794.go
                  index e13e470..636af26 100644
                  --- a/test/fixedbugs/issue22794.go
                  +++ b/test/fixedbugs/issue22794.go
                  @@ -15,7 +15,7 @@
                  i1 := it{Floats: true}
                  if i1.floats { // ERROR "(type it .* field or method floats, but does have Floats)|undefined field or method"
                  }
                  - i2 := &it{floats: false} // ERROR "(but does have Floats)|unknown field|declared but not used"
                  + i2 := &it{floats: false} // ERROR "(but does have Floats)|unknown field|declared and not used"
                  _ = &it{InneR: "foo"} // ERROR "(but does have inner)|unknown field"
                  _ = i2
                  }
                  diff --git a/test/fixedbugs/issue23116.go b/test/fixedbugs/issue23116.go
                  index b4b36d4..1737fee 100644
                  --- a/test/fixedbugs/issue23116.go
                  +++ b/test/fixedbugs/issue23116.go
                  @@ -10,6 +10,6 @@
                  switch x.(type) {
                  }

                  - switch t := x.(type) { // ERROR "declared but not used"
                  + switch t := x.(type) { // ERROR "declared and not used"
                  }
                  }
                  diff --git a/test/fixedbugs/issue23586.go b/test/fixedbugs/issue23586.go
                  index c2d4c9f..c7c82b6 100644
                  --- a/test/fixedbugs/issue23586.go
                  +++ b/test/fixedbugs/issue23586.go
                  @@ -7,7 +7,7 @@
                  // Test that we type-check deferred/go functions even
                  // if they are not called (a common error). Specifically,
                  // we don't want to see errors such as import or variable
                  -// declared but not used.
                  +// declared and not used.

                  package p

                  diff --git a/test/fixedbugs/issue29870b.go b/test/fixedbugs/issue29870b.go
                  index 0a83489..c7cdd8c 100644
                  --- a/test/fixedbugs/issue29870b.go
                  +++ b/test/fixedbugs/issue29870b.go
                  @@ -10,5 +10,5 @@
                  package main

                  func _() {
                  - x := 7 // ERROR ".*x.* declared but not used"
                  + x := 7 // ERROR ".*x.* declared and not used"
                  }
                  diff --git a/test/fixedbugs/issue5957.dir/c.go b/test/fixedbugs/issue5957.dir/c.go
                  index 821b37e..382e234 100644

                  --- a/test/fixedbugs/issue5957.dir/c.go
                  +++ b/test/fixedbugs/issue5957.dir/c.go
                  @@ -1,12 +1,12 @@
                  package p

                  import (
                  - "./a" // ERROR "imported and not used: \x22test/a\x22 as surprise|imported and not used: surprise"
                  - "./b" // ERROR "imported and not used: \x22test/b\x22 as surprise2|imported and not used: surprise2"
                  - b "./b" // ERROR "imported and not used: \x22test/b\x22$|imported and not used: surprise2"
                  - foo "math" // ERROR "imported and not used: \x22math\x22 as foo|imported and not used: math"
                  +	"./a" // ERROR "imported and not used: \x22test/a\x22 as surprise|imported and not used: surprise|\x22test/a\x22 imported as surprise and not used"
                  + "./b" // ERROR "imported and not used: \x22test/b\x22 as surprise2|imported and not used: surprise2|\x22test/b\x22 imported as surprise2 and not used"
                  + b "./b" // ERROR "imported and not used: \x22test/b\x22$|imported and not used: surprise2|\x22test/b\x22 imported and not used"
                  + foo "math" // ERROR "imported and not used: \x22math\x22 as foo|imported and not used: math|\x22math\x22 imported as foo and not used"

                  "fmt" // actually used
                  - "strings" // ERROR "imported and not used: \x22strings\x22|imported and not used: strings"
                  +	"strings" // ERROR "imported and not used: \x22strings\x22|imported and not used: strings|\x22strings\x22 imported and not used"

                  )

                  var _ = fmt.Printf
                  diff --git a/test/import1.go b/test/import1.go
                  index 294ef3a..8a4534b 100644

                  --- a/test/import1.go
                  +++ b/test/import1.go
                  @@ -10,10 +10,10 @@
                  package main

                  import "bufio" // ERROR "previous|not used"
                  -import bufio "os" // ERROR "redeclared|redefinition|incompatible" "imported and not used"
                  +import bufio "os"	// ERROR "redeclared|redefinition|incompatible" "imported and not used|imported as bufio and not used"


                  import (
                  "fmt" // ERROR "previous|not used"
                  - fmt "math" // ERROR "redeclared|redefinition|incompatible" "imported and not used: \x22math\x22 as fmt"
                  - . "math" // GC_ERROR "imported and not used: \x22math\x22$"
                  +	fmt "math"	// ERROR "redeclared|redefinition|incompatible" "imported and not used: \x22math\x22 as fmt|imported as fmt and not used"
                  + . "math" // GC_ERROR "imported and not used: \x22math\x22$|imported and not used"

                  )
                  diff --git a/test/import4.dir/import4.go b/test/import4.dir/import4.go
                  index b9f973f..dafc5e4 100644

                  --- a/test/import4.dir/import4.go
                  +++ b/test/import4.dir/import4.go
                  @@ -9,16 +9,16 @@
                  package main

                  // standard
                  -import "fmt" // ERROR "imported and not used.*fmt"
                  +import "fmt"	// ERROR "imported and not used.*fmt|\x22fmt\x22 imported and not used"


                  // renamed
                  -import X "math" // ERROR "imported and not used.*math"
                  +import X "math"	// ERROR "imported and not used.*math|\x22math\x22 imported as X and not used"


                  // import dot
                  -import . "bufio" // ERROR "imported and not used.*bufio"
                  +import . "bufio"	// ERROR "imported and not used.*bufio|imported and not used"


                  // again, package without anything in it
                  -import "./empty" // ERROR "imported and not used.*empty"
                  -import Z "./empty" // ERROR "imported and not used.*empty"
                  -import . "./empty" // ERROR "imported and not used.*empty"
                  +import "./empty"	// ERROR "imported and not used.*empty|imported and not used"
                  +import Z "./empty" // ERROR "imported and not used.*empty|imported as Z and not used"
                  +import . "./empty" // ERROR "imported and not used.*empty|imported and not used"

                  diff --git a/test/typeswitch2b.go b/test/typeswitch2b.go
                  index 6da0d5f..135ae86 100644
                  --- a/test/typeswitch2b.go
                  +++ b/test/typeswitch2b.go
                  @@ -11,9 +11,9 @@

                  func notused(x interface{}) {
                  // The first t is in a different scope than the 2nd t; it cannot
                  - // be accessed (=> declared but not used error); but it is legal
                  + // be accessed (=> declared and not used error); but it is legal
                  // to declare it.
                  - switch t := 0; t := x.(type) { // ERROR "declared but not used"
                  + switch t := 0; t := x.(type) { // ERROR "declared and not used"
                  case int:
                  _ = t // this is using the t of "t := x.(type)"
                  }

                  To view, visit change 432557. To unsubscribe, or for help writing mail filters, visit settings.

                  Gerrit-Project: go
                  Gerrit-Branch: master
                  Gerrit-Change-Id: Ie71cf662fb5f4648449c64fc51bede298a1bdcbf
                  Gerrit-Change-Number: 432557
                  Gerrit-PatchSet: 13
                  Gerrit-Owner: Robert Griesemer <g...@golang.org>
                  Gerrit-Reviewer: Gopher Robot <go...@golang.org>
                  Gerrit-Reviewer: Robert Findley <rfin...@google.com>
                  Gerrit-Reviewer: Robert Griesemer <g...@google.com>
                  Gerrit-MessageType: merged
                  Reply all
                  Reply to author
                  Forward
                  0 new messages