* Go patch committed: Reword "declared and not used" error message
@ 2020-12-02 16:31 Ian Lance Taylor
0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2020-12-02 16:31 UTC (permalink / raw)
To: gcc-patches, gofrontend-dev
[-- Attachment #1: Type: text/plain, Size: 618 bytes --]
This patch to the Go frontend rewords the "declared and not used"
error message. This is a copy of https://golang.org/cl/203282 in the
gc compiler.
From the CL 203282 description:
"declared and not used" is technically correct, but might confuse
the user. Switching "and" to "but" will hopefully create the
contrast for the users: they did one thing (declaration), but
not the other --- actually using the variable.
This requires updating a couple of tests in the testsuite to the
versions in the source repo.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed
to mainline.
Ian
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 3358 bytes --]
5bd5d85117ce968e68d41a746f917a63ed8e6ae6
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index d6ee8573e92..183e5cae9c9 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-720b8fed93143f284ca04358e1b13c8a3487281e
+6b01f8cdc11d86bd98165c91d6ae101bcf6b9e1a
The first line of this file holds the git revision number of the last
merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc
index 93a4a5773a2..a5e4521469b 100644
--- a/gcc/go/gofrontend/gogo.cc
+++ b/gcc/go/gofrontend/gogo.cc
@@ -3744,7 +3744,7 @@ Check_types_traverse::variable(Named_object* named_object)
&& !var->type()->is_error()
&& (init == NULL || !init->is_error_expression())
&& !Lex::is_invalid_identifier(named_object->name()))
- go_error_at(var->location(), "%qs declared and not used",
+ go_error_at(var->location(), "%qs declared but not used",
named_object->message_name().c_str());
}
return TRAVERSE_CONTINUE;
diff --git a/gcc/go/gofrontend/parse.cc b/gcc/go/gofrontend/parse.cc
index 00ac2f8f48c..b1925ed8ccc 100644
--- a/gcc/go/gofrontend/parse.cc
+++ b/gcc/go/gofrontend/parse.cc
@@ -4817,7 +4817,7 @@ Parse::type_switch_body(Label* label, const Type_switch& type_switch,
}
}
if (!used)
- go_error_at(type_switch.location, "%qs declared and not used",
+ go_error_at(type_switch.location, "%qs declared but not used",
Gogo::message_name(var_name).c_str());
}
return statement;
diff --git a/gcc/testsuite/go.test/test/fixedbugs/bug373.go b/gcc/testsuite/go.test/test/fixedbugs/bug373.go
index e91f26d6ed0..6b7a312097a 100644
--- a/gcc/testsuite/go.test/test/fixedbugs/bug373.go
+++ b/gcc/testsuite/go.test/test/fixedbugs/bug373.go
@@ -1,6 +1,6 @@
// errorcheck
-// Copyright 2011 The Go Authors. All rights reserved.
+// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@@ -9,7 +9,7 @@
package foo
func f(x interface{}) {
- switch t := x.(type) { // ERROR "declared and not used"
+ switch t := x.(type) { // ERROR "declared but not used"
case int:
}
}
diff --git a/gcc/testsuite/go.test/test/typeswitch2.go b/gcc/testsuite/go.test/test/typeswitch2.go
index 6c703076a6f..62c96c8330f 100644
--- a/gcc/testsuite/go.test/test/typeswitch2.go
+++ b/gcc/testsuite/go.test/test/typeswitch2.go
@@ -4,7 +4,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// Verify that various erroneous type switches are caught be the compiler.
+// Verify that various erroneous type switches are caught by the compiler.
// Does not compile.
package main
@@ -26,22 +26,12 @@ func whatis(x interface{}) string {
w()
}:
return "rw"
- case interface { // GCCGO_ERROR "duplicate"
+ case interface { // ERROR "duplicate"
w()
r()
- }: // GC_ERROR "duplicate"
+ }:
return "wr"
}
return ""
}
-
-func notused(x interface{}) {
- // The first t is in a different scope than the 2nd t; it cannot
- // be accessed (=> declared and not used error); but it is legal
- // to declare it.
- switch t := 0; t := x.(type) { // ERROR "declared and not used"
- case int:
- _ = t // this is using the t of "t := x.(type)"
- }
-}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-12-02 16:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-02 16:31 Go patch committed: Reword "declared and not used" error message Ian Lance Taylor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).