Source file test/typeparam/mdempsky/16.go
1 // run 2 3 // Copyright 2022 The Go Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file. 6 7 // Test that type assertion panics mention the real interface type, 8 // not their shape type. 9 10 package main 11 12 import ( 13 "fmt" 14 "runtime" 15 "strings" 16 ) 17 18 func main() { 19 // The exact error message isn't important, but it should mention 20 // `main.T`, not `go.shape.int_0`. 21 if have := F[T](); !strings.Contains(have, "interface { T() main.T }") { 22 fmt.Printf("FAIL: unexpected panic message: %q\n", have) 23 } 24 } 25 26 type T int 27 28 func F[T any]() (res string) { 29 defer func() { 30 res = recover().(runtime.Error).Error() 31 }() 32 _ = interface{ T() T }(nil).(T) 33 return 34 } 35