Skip to content

Commit dbdb335

Browse files
griesemergopherbot
authored andcommitted
go/types, types2: use "undefined type" rather than "<T>" in have/want error messages
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 <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Auto-Submit: Robert Griesemer <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]>
1 parent 142d30b commit dbdb335

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func (check *Checker) typesSummary(list []Type, variadic bool) string {
266266
case t == nil:
267267
fallthrough // should not happen but be cautious
268268
case t == Typ[Invalid]:
269-
s = "<T>"
269+
s = "unknown type"
270270
case isUntyped(t):
271271
if isNumeric(t) {
272272
// Do not imply a specific type requirement:

src/go/types/assignments.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ func (check *Checker) typesSummary(list []Type, variadic bool) string {
260260
case t == nil:
261261
fallthrough // should not happen but be cautious
262262
case t == Typ[Invalid]:
263-
s = "<T>"
263+
s = "unknown type"
264264
case isUntyped(t):
265265
if isNumeric(t) {
266266
// Do not imply a specific type requirement:
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package p
6+
7+
func _() (int, UndefinedType /* ERROR "undefined: UndefinedType" */ , string) {
8+
return 0 // ERROR "not enough return values\n\thave (number)\n\twant (int, unknown type, string)"
9+
}
10+
11+
func _() (int, UndefinedType /* ERROR "undefined: UndefinedType" */ ) {
12+
return 0, 1, 2 // ERROR "too many return values\n\thave (number, number, number)\n\twant (int, unknown type)"
13+
}
14+
15+
// test case from issue
16+
func _() UndefinedType /* ERROR "undefined: UndefinedType" */ {
17+
return // ERROR "not enough return values\n\thave ()\n\twant (unknown type)"
18+
}

0 commit comments

Comments
 (0)