]> Cypherpunks.ru repositories - gostls13.git/commit
go/types, types2: better error message for cases of reverse type inference
authorRobert Griesemer <gri@golang.org>
Mon, 11 Dec 2023 21:28:25 +0000 (13:28 -0800)
committerGopher Robot <gobot@golang.org>
Tue, 12 Dec 2023 18:44:28 +0000 (18:44 +0000)
commit2643a591728b0fd2bd1e007443442254d1200201
treed4e04ce5851cbf07ad6c01ab45c0d6c9afe5b05e
parent699807f323739582f37814c29fece6e3564eb13d
go/types, types2: better error message for cases of reverse type inference

Introduce a new type "target" to pass around target types together
with a suitable description (typically a variable name) for a better
error message.

As a side effect, using a specific type (target), rather than just Type
avoids accidental confusion with other types.

Use the target type description for a better error message in some
cases.

The error message can be further improved by flipping the order of
the sentence (for another CL to keep this one small and simple).

Also, and unrelated to this fix, remove the first argument to errorf
in infer.go: the argument is always "type" (there's only one call).

For #60747.

Change-Id: I2118d0fe9e2b4aac959371941064e0e9ca7b3b6e
Reviewed-on: https://go-review.googlesource.com/c/go/+/548995
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
13 files changed:
src/cmd/compile/internal/types2/assignments.go
src/cmd/compile/internal/types2/call.go
src/cmd/compile/internal/types2/decl.go
src/cmd/compile/internal/types2/expr.go
src/cmd/compile/internal/types2/infer.go
src/go/types/assignments.go
src/go/types/call.go
src/go/types/decl.go
src/go/types/expr.go
src/go/types/infer.go
src/internal/types/testdata/examples/inference2.go
src/internal/types/testdata/fixedbugs/issue60688.go
src/internal/types/testdata/fixedbugs/issue60747.go [new file with mode: 0644]