Skip to content

Commit

Permalink
test: add extra typeswitch tests that cause duplicate cases
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
danscales committed Dec 8, 2021
1 parent 85a8e17 commit c1c303f
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 6 deletions.
4 changes: 4 additions & 0 deletions test/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions test/typeparam/typeswitch1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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))
}
2 changes: 2 additions & 0 deletions test/typeparam/typeswitch1.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ int
int32/int16
struct{T,T}
other
T
int32/int16
2 changes: 2 additions & 0 deletions test/typeparam/typeswitch2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
2 changes: 2 additions & 0 deletions test/typeparam/typeswitch2.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion test/typeparam/typeswitch3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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))
}
3 changes: 3 additions & 0 deletions test/typeparam/typeswitch3.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
myint 6
T 7
other 8
T 8
other 7
other 9
11 changes: 8 additions & 3 deletions test/typeparam/typeswitch4.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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))
}
3 changes: 3 additions & 0 deletions test/typeparam/typeswitch4.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
other 6
T/myint32 7
T/myint32 8
T/myint32 9
T/myint32 10
other 42

0 comments on commit c1c303f

Please sign in to comment.