Source file test/typeparam/issue51521.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  package main
     8  
     9  import (
    10  	"fmt"
    11  	"strings"
    12  )
    13  
    14  type I interface{ M() }
    15  
    16  func F[P I](p P) { defer catch(); p.M() }
    17  func G[T any]()  { defer catch(); interface{ M() T }.M(nil) }
    18  
    19  func main() {
    20  	F[I](nil)
    21  	G[int]()
    22  }
    23  
    24  func 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  

View as plain text