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
7package main
8
9import (
10	"fmt"
11	"strings"
12)
13
14type I interface{ M() }
15
16func F[P I](p P) { defer catch(); p.M() }
17func G[T any]()  { defer catch(); interface{ M() T }.M(nil) }
18
19func main() {
20	F[I](nil)
21	G[int]()
22}
23
24func catch() {
25	err := recover()
26	if err, ok := err.(error); ok && strings.Contains(err.Error(), "nil pointer dereference") {
27		return
28	}
29	fmt.Println("FAIL", err)
30}
31