]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: use "undefined type" rather than "<T>" in have/want error messages
authorRobert Griesemer <gri@golang.org>
Fri, 3 Mar 2023 18:43:02 +0000 (10:43 -0800)
committerGopher Robot <gobot@golang.org>
Mon, 6 Mar 2023 18:21:51 +0000 (18:21 +0000)
In assignments and return statements, if we have the wrong number
of LHS or return values, we report the pattern that we have and
the pattern that we want. For untyped constants we use "number"
(to be not overly specific). For unknown types (due to earlier
errors), now use "unknown type" rather than the (cryptic) "<T>".

Fixes #58742.

Change-Id: I69c84ee29fb64badb0121e26a96f003b381024aa
Reviewed-on: https://go-review.googlesource.com/c/go/+/473255
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/types2/assignments.go
src/go/types/assignments.go
src/internal/types/testdata/fixedbugs/issue58742.go [new file with mode: 0644]

index 35fb3f5b143a38184b825fd4e6d9ab89884d9fbe..dd814c2e83d948c57d59e00c96a602949f784cdc 100644 (file)
@@ -266,7 +266,7 @@ func (check *Checker) typesSummary(list []Type, variadic bool) string {
                case t == nil:
                        fallthrough // should not happen but be cautious
                case t == Typ[Invalid]:
-                       s = "<T>"
+                       s = "unknown type"
                case isUntyped(t):
                        if isNumeric(t) {
                                // Do not imply a specific type requirement:
index a7a247b99fe2cc35643edbd4d6d21a7b5f5d5b28..a3b28d0e22a50137eb50bfc728467145d8731efe 100644 (file)
@@ -260,7 +260,7 @@ func (check *Checker) typesSummary(list []Type, variadic bool) string {
                case t == nil:
                        fallthrough // should not happen but be cautious
                case t == Typ[Invalid]:
-                       s = "<T>"
+                       s = "unknown type"
                case isUntyped(t):
                        if isNumeric(t) {
                                // Do not imply a specific type requirement:
diff --git a/src/internal/types/testdata/fixedbugs/issue58742.go b/src/internal/types/testdata/fixedbugs/issue58742.go
new file mode 100644 (file)
index 0000000..b649a49
--- /dev/null
@@ -0,0 +1,18 @@
+// Copyright 2023 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.
+
+package p
+
+func _() (int, UndefinedType /* ERROR "undefined: UndefinedType" */ , string)  {
+       return 0 // ERROR "not enough return values\n\thave (number)\n\twant (int, unknown type, string)"
+}
+
+func _() (int, UndefinedType /* ERROR "undefined: UndefinedType" */ ) {
+       return 0, 1, 2 // ERROR "too many return values\n\thave (number, number, number)\n\twant (int, unknown type)"
+}
+
+// test case from issue
+func _() UndefinedType /* ERROR "undefined: UndefinedType" */ {
+       return // ERROR "not enough return values\n\thave ()\n\twant (unknown type)"
+}