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 <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>
This commit is contained in:
Robert Griesemer 2023-03-03 10:43:02 -08:00 committed by Gopher Robot
parent 142d30b2cb
commit dbdb3359b5
3 changed files with 20 additions and 2 deletions

View 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:

View 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:

View File

@ -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)"
}