]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.19] test: improve generic type assertion test
authorMatthew Dempsky <mdempsky@google.com>
Mon, 1 Aug 2022 20:23:36 +0000 (13:23 -0700)
committerDmitri Shuralyov <dmitshur@golang.org>
Mon, 1 Aug 2022 22:43:15 +0000 (22:43 +0000)
The test added in CL 420674 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 <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
(cherry picked from commit f2a9f3e2e0ce7e582d226ad9a41d3c36b146fc25)
Reviewed-on: https://go-review.googlesource.com/c/go/+/420675
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
test/typeparam/issue54135.go

index dffef60d0d7e2037cb25aeac55d192141ccba034..b489a514165d234d8c9ca7b98b32b0956ce4bbf5 100644 (file)
@@ -1,4 +1,4 @@
-// compile
+// run
 
 // Copyright 2022 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
@@ -19,8 +19,12 @@ type Baz interface {
 }
 
 func check[T comparable](p Bar[T]) {
-       _, _ = p.(any)
-       _, _ = p.(Baz)
+       if x, ok := p.(any); !ok || x != p {
+               panic("FAIL")
+       }
+       if _, ok := p.(Baz); ok {
+               panic("FAIL")
+       }
 }
 
 func main() {