blob: aa9544e285af803dafdf5c7103d98f05fccda50f [file] [edit]
-- Convert a single rune to a string --
// This code relies on pre-go1.28 string(integer) conversion rules;
// the build tag downgrades the file to go1.21 (the oldest version
// to which a build tag can downgrade).
//go:build go1.21
package fix
type str = string
// The conversion is dropped when T is string, even via an alias...
func _(x int16) str {
return str(rune(x)) // want `conversion from int16 to str \(string\) yields...`
}
// ...but not when T is a type parameter whose only term is string.
func _[S ~string](x int16) S {
return S(rune(x)) // want `conversion from int16 to string \(in S\) yields...`
}
-- Format number as decimal (changes behavior) --
// This code relies on pre-go1.28 string(integer) conversion rules;
// the build tag downgrades the file to go1.21 (the oldest version
// to which a build tag can downgrade).
//go:build go1.21
package fix
import "fmt"
type str = string
// The conversion is dropped when T is string, even via an alias...
func _(x int16) str {
return fmt.Sprintf("%d", x) // want `conversion from int16 to str \(string\) yields...`
}
// ...but not when T is a type parameter whose only term is string.
func _[S ~string](x int16) S {
return S(fmt.Sprintf("%d", x)) // want `conversion from int16 to string \(in S\) yields...`
}