Skip to content

Commit f2a9f3e

Browse files
mdempskygopherbot
authored andcommitted
test: improve generic type assertion test
The test added in CL 420394 only tested that the type assertions compiled at all. This CL changes it into a run test to make sure the type assertions compile and also run correctly. Updates #54135. Change-Id: Id17469faad1bb55ff79b0bb4163ef50179330033 Reviewed-on: https://go-review.googlesource.com/c/go/+/420421 Run-TryBot: Matthew Dempsky <[email protected]> Reviewed-by: Keith Randall <[email protected]> Auto-Submit: Matthew Dempsky <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 27038b7 commit f2a9f3e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

test/typeparam/issue54135.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile
1+
// run
22

33
// Copyright 2022 The Go Authors. All rights reserved.
44
// Use of this source code is governed by a BSD-style
@@ -19,8 +19,12 @@ type Baz interface {
1919
}
2020

2121
func check[T comparable](p Bar[T]) {
22-
_, _ = p.(any)
23-
_, _ = p.(Baz)
22+
if x, ok := p.(any); !ok || x != p {
23+
panic("FAIL")
24+
}
25+
if _, ok := p.(Baz); ok {
26+
panic("FAIL")
27+
}
2428
}
2529

2630
func main() {

0 commit comments

Comments
 (0)