mirror of
https://github.com/golang/go
synced 2024-11-22 20:04:47 -07:00
f2a9f3e2e0
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 <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>
33 lines
478 B
Go
33 lines
478 B
Go
// run
|
|
|
|
// Copyright 2022 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
type Foo struct{}
|
|
|
|
func (Foo) Blanker() {}
|
|
|
|
type Bar[T any] interface {
|
|
Blanker()
|
|
}
|
|
|
|
type Baz interface {
|
|
Some()
|
|
}
|
|
|
|
func check[T comparable](p Bar[T]) {
|
|
if x, ok := p.(any); !ok || x != p {
|
|
panic("FAIL")
|
|
}
|
|
if _, ok := p.(Baz); ok {
|
|
panic("FAIL")
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
check[int](Foo{})
|
|
}
|