mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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>
37 lines
1.4 KiB
Go
37 lines
1.4 KiB
Go
// errorcheck
|
|
|
|
// Copyright 2021 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
|
|
|
|
var s string
|
|
var b bool
|
|
var i int
|
|
var iface interface{}
|
|
|
|
var (
|
|
_ = "" + b // ERROR "invalid operation.*mismatched types.*untyped string and bool"
|
|
_ = "" + i // ERROR "invalid operation.*mismatched types.*untyped string and int"
|
|
_ = "" + nil // ERROR "invalid operation.*mismatched types.*untyped string and nil|(untyped nil)"
|
|
)
|
|
|
|
var (
|
|
_ = s + false // ERROR "invalid operation.*mismatched types.*string and untyped bool"
|
|
_ = s + 1 // ERROR "invalid operation.*mismatched types.*string and untyped int"
|
|
_ = s + nil // ERROR "invalid operation.*mismatched types.*string and nil|(untyped nil)"
|
|
)
|
|
|
|
var (
|
|
_ = "" + false // ERROR "invalid operation.*mismatched types.*untyped string and untyped bool"
|
|
_ = "" + 1 // ERROR "invalid operation.*mismatched types.*untyped string and untyped int"
|
|
)
|
|
|
|
var (
|
|
_ = b + 1 // ERROR "invalid operation.*mismatched types.*bool and untyped int"
|
|
_ = i + false // ERROR "invalid operation.*mismatched types.*int and untyped bool"
|
|
_ = iface + 1 // ERROR "invalid operation.*mismatched types.*interface *{} and untyped int"
|
|
_ = iface + 1.0 // ERROR "invalid operation.*mismatched types.*interface *{} and untyped float"
|
|
_ = iface + false // ERROR "invalid operation.*mismatched types.*interface *{} and bool"
|
|
)
|