From f2a9f3e2e0ce7e582d226ad9a41d3c36b146fc25 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Mon, 1 Aug 2022 13:23:36 -0700 Subject: [PATCH] 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 Reviewed-by: Keith Randall Auto-Submit: Matthew Dempsky TryBot-Result: Gopher Robot Reviewed-by: Keith Randall --- test/typeparam/issue54135.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/typeparam/issue54135.go b/test/typeparam/issue54135.go index dffef60d0d..b489a51416 100644 --- a/test/typeparam/issue54135.go +++ b/test/typeparam/issue54135.go @@ -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() {