]> Cypherpunks repositories - gostls13.git/commit
go/types, types2: better error messages for certain type mismatches
authorRobert Griesemer <gri@google.com>
Wed, 18 Jun 2025 00:09:27 +0000 (17:09 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 24 Jul 2025 16:04:33 +0000 (09:04 -0700)
commitcae45167b79ec3838f0cabb19394bcd99810f79a
treed29bf1cc53a4653c77bb9d0a35b408f4a0a901c2
parent2ddf542e4c30b2d4886482c44b57259f5b461158
go/types, types2: better error messages for certain type mismatches

When an untyped operand of a (typically binary) operation does not
match the type of the operand and an implicit conversion is not
possible, the error message should report a "type mismatch".

The type-checkers mostly did so, but not for untyped numeric types
to other types (e.g. an untyped int vs a function); in those cases
it reported that the (impossible) conversion failed.

Fix this for numeric types.
This also improves the position and messages for some incorrect
min/max built-in calls.

Fixes #73428.

Change-Id: I8af071918b73fcc72f16cc61858d7baca57fc259
Reviewed-on: https://go-review.googlesource.com/c/go/+/682495
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Mark Freeman <mark@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
src/cmd/compile/internal/types2/expr.go
src/go/types/expr.go
src/internal/types/errors/codes.go
src/internal/types/testdata/check/builtins1.go
src/internal/types/testdata/check/expr2.go
src/internal/types/testdata/fixedbugs/issue60434.go
src/internal/types/testdata/fixedbugs/issue73428.go [new file with mode: 0644]
test/fixedbugs/issue46749.go