mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
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:
parent
142d30b2cb
commit
dbdb3359b5
@ -266,7 +266,7 @@ func (check *Checker) typesSummary(list []Type, variadic bool) string {
|
|||||||
case t == nil:
|
case t == nil:
|
||||||
fallthrough // should not happen but be cautious
|
fallthrough // should not happen but be cautious
|
||||||
case t == Typ[Invalid]:
|
case t == Typ[Invalid]:
|
||||||
s = "<T>"
|
s = "unknown type"
|
||||||
case isUntyped(t):
|
case isUntyped(t):
|
||||||
if isNumeric(t) {
|
if isNumeric(t) {
|
||||||
// Do not imply a specific type requirement:
|
// Do not imply a specific type requirement:
|
||||||
|
@ -260,7 +260,7 @@ func (check *Checker) typesSummary(list []Type, variadic bool) string {
|
|||||||
case t == nil:
|
case t == nil:
|
||||||
fallthrough // should not happen but be cautious
|
fallthrough // should not happen but be cautious
|
||||||
case t == Typ[Invalid]:
|
case t == Typ[Invalid]:
|
||||||
s = "<T>"
|
s = "unknown type"
|
||||||
case isUntyped(t):
|
case isUntyped(t):
|
||||||
if isNumeric(t) {
|
if isNumeric(t) {
|
||||||
// Do not imply a specific type requirement:
|
// Do not imply a specific type requirement:
|
||||||
|
18
src/internal/types/testdata/fixedbugs/issue58742.go
vendored
Normal file
18
src/internal/types/testdata/fixedbugs/issue58742.go
vendored
Normal 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)"
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user