test: add extra typeswitch tests that cause duplicate cases

Augmented some of the typeswitch*.go tests so that some instantiations
have duplicate cases, in order to ensure we're testing that.

Spacing changes in the tests are due to gofmt.

Change-Id: I5d3678813505c520c544281d4ac8a62ce7e236ad
Reviewed-on: https://go-review.googlesource.com/c/go/+/370155
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Dan Scales 2021-12-07 15:59:22 -08:00
parent 85a8e1786a
commit c1c303f6f8
9 changed files with 34 additions and 6 deletions

View file

@ -2183,6 +2183,10 @@ var unifiedFailures = setOf(
"fixedbugs/issue49767.go", // unified IR doesn't report channel element too large
"fixedbugs/issue49814.go", // unified IR doesn't report array type too large
"typeparam/issue50002.go", // pure stenciling leads to a static type assertion error
"typeparam/typeswitch1.go", // duplicate case failure due to stenciling
"typeparam/typeswitch2.go", // duplicate case failure due to stenciling
"typeparam/typeswitch3.go", // duplicate case failure due to stenciling
"typeparam/typeswitch4.go", // duplicate case failure due to stenciling
)
func setOf(keys ...string) map[string]bool {

View file

@ -14,7 +14,7 @@ func f[T any](i interface{}) {
println("int")
case int32, int16:
println("int32/int16")
case struct { a, b T }:
case struct{ a, b T }:
println("struct{T,T}")
default:
println("other")
@ -24,6 +24,8 @@ func main() {
f[float64](float64(6))
f[float64](int(7))
f[float64](int32(8))
f[float64](struct{a, b float64}{a:1, b:2})
f[float64](struct{ a, b float64 }{a: 1, b: 2})
f[float64](int8(9))
f[int32](int32(7))
f[int](int32(7))
}

View file

@ -3,3 +3,5 @@ int
int32/int16
struct{T,T}
other
T
int32/int16

View file

@ -28,4 +28,6 @@ func main() {
f[float64](int32(8))
f[float64](struct{ a, b float64 }{a: 1, b: 2})
f[float64](int8(9))
f[int32](int32(7))
f[int](int32(7))
}

View file

@ -3,3 +3,5 @@ int 7
int32/int16 8
struct{T,T} +1.000000e+000 +2.000000e+000
other 9
T 7
int32/int16 7

View file

@ -6,16 +6,18 @@
package main
type I interface { foo() int }
type I interface{ foo() int }
type myint int
func (x myint) foo() int { return int(x) }
type myfloat float64
func (x myfloat) foo() int { return int(x) }
type myint32 int32
func (x myint32) foo() int { return int(x) }
func f[T I](i I) {
@ -32,4 +34,7 @@ func main() {
f[myfloat](myint(6))
f[myfloat](myfloat(7))
f[myfloat](myint32(8))
f[myint32](myint32(8))
f[myint32](myfloat(7))
f[myint](myint32(9))
}

View file

@ -1,3 +1,6 @@
myint 6
T 7
other 8
T 8
other 7
other 9

View file

@ -6,16 +6,18 @@
package main
type I interface { foo() int }
type I interface{ foo() int }
type myint int
func (x myint) foo() int {return int(x)}
func (x myint) foo() int { return int(x) }
type myfloat float64
func (x myfloat) foo() int {return int(x)}
func (x myfloat) foo() int { return int(x) }
type myint32 int32
func (x myint32) foo() int { return int(x) }
func f[T I](i I) {
@ -30,4 +32,7 @@ func main() {
f[myfloat](myint(6))
f[myfloat](myfloat(7))
f[myfloat](myint32(8))
f[myint32](myint32(9))
f[myint](myint32(10))
f[myint](myfloat(42))
}

View file

@ -1,3 +1,6 @@
other 6
T/myint32 7
T/myint32 8
T/myint32 9
T/myint32 10
other 42