This matches current compiler behavior.
For #55326.
Change-Id: I660bd15f13a8d9eb00fafa937f8261e664b0e065
Reviewed-on: https://go-review.googlesource.com/c/go/+/433276
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
return true
}
if !constConvertibleTo(u, nil) {
- cause = check.sprintf("cannot convert %s to %s (in %s)", x, u, T)
+ cause = check.sprintf("cannot convert %s to type %s (in %s)", x, u, T)
return false
}
return true
if !ok {
var err error_
err.code = _InvalidConversion
- if check.conf.CompilerErrorMessages {
- if cause != "" {
- // Add colon at end of line if we have a following cause.
- err.errorf(x, "cannot convert %s to type %s:", x, T)
- err.errorf(nopos, cause)
- } else {
- err.errorf(x, "cannot convert %s to type %s", x, T)
- }
+ if cause != "" {
+ err.errorf(x, "cannot convert %s to type %s:", x, T)
+ err.errorf(nopos, cause)
} else {
- err.errorf(x, "cannot convert %s to %s", x, T)
- if cause != "" {
- err.errorf(nopos, cause)
- }
+ err.errorf(x, "cannot convert %s to type %s", x, T)
}
check.report(&err)
x.mode = invalid
return false // no specific types
}
if !x.convertibleTo(check, T.typ, cause) {
- errorf("cannot convert %s (in %s) to %s (in %s)", V.typ, Vp, T.typ, Tp)
+ errorf("cannot convert %s (in %s) to type %s (in %s)", V.typ, Vp, T.typ, Tp)
return false
}
return true
}
x.typ = V.typ
if !x.convertibleTo(check, T, cause) {
- errorf("cannot convert %s (in %s) to %s", V.typ, Vp, T)
+ errorf("cannot convert %s (in %s) to type %s", V.typ, Vp, T)
return false
}
return true
return false // no specific types
}
if !x.convertibleTo(check, T.typ, cause) {
- errorf("cannot convert %s to %s (in %s)", x.typ, T.typ, Tp)
+ errorf("cannot convert %s to type %s (in %s)", x.typ, T.typ, Tp)
return false
}
return true
}
func (check *Checker) invalidConversion(code errorCode, x *operand, target Type) {
- msg := "cannot convert %s to %s"
+ msg := "cannot convert %s to type %s"
switch code {
case _TruncatedFloat:
msg = "%s truncated to %s"
return true
}
if !constConvertibleTo(u, nil) {
- cause = check.sprintf("cannot convert %s to %s (in %s)", x, u, T)
+ cause = check.sprintf("cannot convert %s to type %s (in %s)", x, u, T)
return false
}
return true
if !ok {
var err error_
err.code = _InvalidConversion
- if compilerErrorMessages {
- if cause != "" {
- // Add colon at end of line if we have a following cause.
- err.errorf(x.Pos(), "cannot convert %s to type %s:", x, T)
- err.errorf(token.NoPos, cause)
- } else {
- err.errorf(x.Pos(), "cannot convert %s to type %s", x, T)
- }
+ if cause != "" {
+ err.errorf(x.Pos(), "cannot convert %s to type %s:", x, T)
+ err.errorf(token.NoPos, cause)
} else {
- err.errorf(x.Pos(), "cannot convert %s to %s", x, T)
- if cause != "" {
- err.errorf(token.NoPos, cause)
- }
+ err.errorf(x.Pos(), "cannot convert %s to type %s", x, T)
}
check.report(&err)
x.mode = invalid
return false // no specific types
}
if !x.convertibleTo(check, T.typ, cause) {
- errorf("cannot convert %s (in %s) to %s (in %s)", V.typ, Vp, T.typ, Tp)
+ errorf("cannot convert %s (in %s) to type %s (in %s)", V.typ, Vp, T.typ, Tp)
return false
}
return true
}
x.typ = V.typ
if !x.convertibleTo(check, T, cause) {
- errorf("cannot convert %s (in %s) to %s", V.typ, Vp, T)
+ errorf("cannot convert %s (in %s) to type %s", V.typ, Vp, T)
return false
}
return true
return false // no specific types
}
if !x.convertibleTo(check, T.typ, cause) {
- errorf("cannot convert %s to %s (in %s)", x.typ, T.typ, Tp)
+ errorf("cannot convert %s to type %s (in %s)", x.typ, T.typ, Tp)
return false
}
return true
}
func (check *Checker) invalidConversion(code errorCode, x *operand, target Type) {
- msg := "cannot convert %s to %s"
+ msg := "cannot convert %s to type %s"
switch code {
case _TruncatedFloat:
msg = "%s truncated to %s"
unsafe.Slice(1, 2, 3) // ERROR too many arguments
unsafe.Slice(1 /* ERROR is not a pointer */ , 2)
unsafe.Slice(nil /* ERROR nil is not a pointer */ , 0)
- unsafe.Slice(&x, "foo" /* ERROR cannot convert .* to int */ )
+ unsafe.Slice(&x, "foo" /* ERROR cannot convert .* to type int */ )
unsafe.Slice(&x, 1.2 /* ERROR truncated to int */ )
unsafe.Slice(&x, - /* ERROR must not be negative */ 1)
unsafe /* ERROR not used */ .Slice(&x, 0)
unsafe.String() // ERROR not enough arguments
unsafe.String(1, 2, 3) // ERROR too many arguments
unsafe.String(1 /* ERROR cannot use 1 */ , 2)
- unsafe.String(&b, "foo" /* ERROR cannot convert .* to int */ )
+ unsafe.String(&b, "foo" /* ERROR cannot convert .* to type int */ )
unsafe.String(&b, 1.2 /* ERROR truncated to int */ )
unsafe.String(&b, - /* ERROR must not be negative */ 1)
unsafe /* ERROR not used */ .String(&b, 0)
func Add1024[T integer](s []T) {
for i, v := range s {
- s[i] = v + 1024 // ERROR cannot convert 1024 \(untyped int constant\) to T
+ s[i] = v + 1024 // ERROR cannot convert 1024 \(untyped int constant\) to type T
}
}
func f[T interface{ int8 }]() {
- println(T(1024 /* ERROR cannot convert 1024 \(untyped int value\) to T */))
+ println(T(1024 /* ERROR cannot convert 1024 \(untyped int value\) to type T */))
}
T1 []int,
T2 ~float64 | ~complex128 | chan int,
]() {
- _ = T0(nil /* ERROR cannot convert nil to T0 */ )
- _ = T1(1 /* ERROR cannot convert 1 .* to T1 */ )
- _ = T2(2 /* ERROR cannot convert 2 .* to T2 */ )
+ _ = T0(nil /* ERROR cannot convert nil to type T0 */ )
+ _ = T1(1 /* ERROR cannot convert 1 .* to type T1 */ )
+ _ = T2(2 /* ERROR cannot convert 2 .* to type T2 */ )
}
// test case from issue
func _[T ~string]() T { return T('a') }
func _[T ~int | ~string]() T { return T('a') }
-func _[T ~byte | ~int | ~string]() T { return T(256 /* ERROR cannot convert 256 .* to T */) }
+func _[T ~byte | ~int | ~string]() T { return T(256 /* ERROR cannot convert 256 .* to type T */) }
// implicit conversions never convert to string
func _[T ~string]() {
T3 ~int | ~float64 | ~bool,
T4 ~int | ~string,
]() {
- _ = T1(0 /* ERROR cannot convert 0 .* to T1\n\tT1 does not contain specific types */)
- _ = T2(1 /* ERROR cannot convert 1 .* to T2\n\tT2 does not contain specific types */)
- _ = T3(2 /* ERROR cannot convert 2 .* to T3\n\tcannot convert 2 .* to bool \(in T3\) */)
- _ = T4(3.14 /* ERROR cannot convert 3.14 .* to T4\n\tcannot convert 3.14 .* to int \(in T4\) */)
+ _ = T1(0 /* ERROR cannot convert 0 .* to type T1:\n\tT1 does not contain specific types */)
+ _ = T2(1 /* ERROR cannot convert 1 .* to type T2:\n\tT2 does not contain specific types */)
+ _ = T3(2 /* ERROR cannot convert 2 .* to type T3:\n\tcannot convert 2 .* to type bool \(in T3\) */)
+ _ = T4(3.14 /* ERROR cannot convert 3.14 .* to type T4:\n\tcannot convert 3.14 .* to type int \(in T4\) */)
}
// "x is assignable to T"
func _[X Foo | Bar, T Bar](x X) T { return T(x) }
func _[X Foo, T Foo | Bar](x X) T { return T(x) }
func _[X Foo, T Far](x X) T {
- return T(x /* ERROR cannot convert x \(variable of type X constrained by Foo\) to T\n\tcannot convert Foo \(in X\) to Far \(in T\) */)
+ return T(x /* ERROR cannot convert x \(variable of type X constrained by Foo\) to type T:\n\tcannot convert Foo \(in X\) to type Far \(in T\) */)
}
// "x's type and T are unnamed pointer types and their pointer base types
func _[X ~*Foo | ~*Bar, T ~*Bar](x X) T { return T(x) }
func _[X ~*Foo, T ~*Foo | ~*Bar](x X) T { return T(x) }
func _[X ~*Foo, T ~*Far](x X) T {
- return T(x /* ERROR cannot convert x \(variable of type X constrained by ~\*Foo\) to T\n\tcannot convert \*Foo \(in X\) to \*Far \(in T\) */)
+ return T(x /* ERROR cannot convert x \(variable of type X constrained by ~\*Foo\) to type T:\n\tcannot convert \*Foo \(in X\) to type \*Far \(in T\) */)
}
// Verify that the defined types in constraints are considered for the rule above.
func _[X, T Integer | Unsigned | Float](x X) T { return T(x) }
func _[X, T Integer | ~string](x X) T {
- return T(x /* ERROR cannot convert x \(variable of type X constrained by Integer \| ~string\) to T\n\tcannot convert string \(in X\) to int \(in T\) */)
+ return T(x /* ERROR cannot convert x \(variable of type X constrained by Integer \| ~string\) to type T:\n\tcannot convert string \(in X\) to type int \(in T\) */)
}
// "x's type and T are both complex types"
func _[X, T Complex](x X) T { return T(x) }
func _[X, T Float | Complex](x X) T {
- return T(x /* ERROR cannot convert x \(variable of type X constrained by Float \| Complex\) to T\n\tcannot convert float32 \(in X\) to complex64 \(in T\) */)
+ return T(x /* ERROR cannot convert x \(variable of type X constrained by Float \| Complex\) to type T:\n\tcannot convert float32 \(in X\) to type complex64 \(in T\) */)
}
// "x is an integer or a slice of bytes or runes and T is a string type"
func _[X Integer](x X) string { return string(x) }
func _[X Integer](x X) myString { return myString(x) }
func _[X Integer](x X) *string {
- return (*string)(x /* ERROR cannot convert x \(variable of type X constrained by Integer\) to \*string\n\tcannot convert int \(in X\) to \*string */)
+ return (*string)(x /* ERROR cannot convert x \(variable of type X constrained by Integer\) to type \*string:\n\tcannot convert int \(in X\) to type \*string */)
}
func _[T ~string](x []byte) T { return T(x) }
func _[X ~[]rune, T ~string](x X) T { return T(x) }
func _[X Integer | ~[]byte | ~[]rune, T ~string](x X) T { return T(x) }
func _[X Integer | ~[]byte | ~[]rune, T ~*string](x X) T {
- return T(x /* ERROR cannot convert x \(variable of type X constrained by Integer \| ~\[\]byte \| ~\[\]rune\) to T\n\tcannot convert int \(in X\) to \*string \(in T\) */)
+ return T(x /* ERROR cannot convert x \(variable of type X constrained by Integer \| ~\[\]byte \| ~\[\]rune\) to type T:\n\tcannot convert int \(in X\) to type \*string \(in T\) */)
}
// "x is a string and T is a slice of bytes or runes"
func _[T ~[]byte](x string) T { return T(x) }
func _[T ~[]rune](x string) T { return T(x) }
func _[T ~[]rune](x *string) T {
- return T(x /* ERROR cannot convert x \(variable of type \*string\) to T\n\tcannot convert \*string to \[\]rune \(in T\) */)
+ return T(x /* ERROR cannot convert x \(variable of type \*string\) to type T:\n\tcannot convert \*string to type \[\]rune \(in T\) */)
}
func _[X ~string, T ~[]byte](x X) T { return T(x) }
func _[X ~string, T ~[]rune](x X) T { return T(x) }
func _[X ~string, T ~[]byte | ~[]rune](x X) T { return T(x) }
func _[X ~*string, T ~[]byte | ~[]rune](x X) T {
- return T(x /* ERROR cannot convert x \(variable of type X constrained by ~\*string\) to T\n\tcannot convert \*string \(in X\) to \[\]byte \(in T\) */)
+ return T(x /* ERROR cannot convert x \(variable of type X constrained by ~\*string\) to type T:\n\tcannot convert \*string \(in X\) to type \[\]byte \(in T\) */)
}
// package unsafe:
func _[X ~uintptr](x X) unsafe.Pointer { return unsafe.Pointer(x) }
func _[T unsafe.Pointer](x myUintptr) T { return T(x) }
func _[T unsafe.Pointer](x int64) T {
- return T(x /* ERROR cannot convert x \(variable of type int64\) to T\n\tcannot convert int64 to unsafe\.Pointer \(in T\) */)
+ return T(x /* ERROR cannot convert x \(variable of type int64\) to type T:\n\tcannot convert int64 to type unsafe\.Pointer \(in T\) */)
}
// "and vice versa"
func _[X unsafe.Pointer](x X) uintptr { return uintptr(x) }
func _[X unsafe.Pointer](x X) myUintptr { return myUintptr(x) }
func _[X unsafe.Pointer](x X) int64 {
- return int64(x /* ERROR cannot convert x \(variable of type X constrained by unsafe\.Pointer\) to int64\n\tcannot convert unsafe\.Pointer \(in X\) to int64 */)
+ return int64(x /* ERROR cannot convert x \(variable of type X constrained by unsafe\.Pointer\) to type int64:\n\tcannot convert unsafe\.Pointer \(in X\) to type int64 */)
}
// "x is a slice, T is an array or pointer-to-array type,