Text file src/go/doc/testdata/generics.1.golden

     1  // Package generics contains the new syntax supporting generic ...
     2  PACKAGE generics
     3  
     4  IMPORTPATH
     5  	testdata/generics
     6  
     7  FILENAMES
     8  	testdata/generics.go
     9  
    10  FUNCTIONS
    11  	// AnotherFunc has an implicit constraint interface.  Neither type ...
    12  	func AnotherFunc[T ~struct{ f int }](_ struct{ f int })
    13  
    14  	// Func has an instantiated constraint.
    15  	func Func[T Constraint[string, Type[int]]]()
    16  
    17  	// Single is not a factory function.
    18  	func Single[T any]() *T
    19  
    20  	// Slice is not a factory function.
    21  	func Slice[T any]() []T
    22  
    23  
    24  TYPES
    25  	// AFuncType demonstrates filtering of parameters and type ...
    26  	type AFuncType[T ~struct{ f int }] func(_ struct{ f int })
    27  
    28  	// Constraint is a constraint interface with two type parameters.
    29  	type Constraint[P, Q interface{ string | ~int | Type[int] }] interface {
    30  		~int | ~byte | Type[string]
    31  		M() P
    32  	}
    33  
    34  	// NewEmbeddings demonstrates how we filter the new embedded ...
    35  	type NewEmbeddings interface {
    36  		string	// should not be filtered
    37  		int16
    38  		struct{ f int }
    39  		~struct{ f int }
    40  		*struct{ f int }
    41  		struct{ f int } | ~struct{ f int }
    42  	}
    43  
    44  	// Parameterized types should be shown.
    45  	type Type[P any] struct {
    46  		Field P
    47  	}
    48  
    49  	// Variables with an instantiated type should be shown.
    50  	var X Type[int]
    51  
    52  	// Constructors for parameterized types should be shown.
    53  	func Constructor[lowerCase any]() Type[lowerCase]
    54  
    55  	// MethodA uses a different name for its receiver type parameter.
    56  	func (t Type[A]) MethodA(p A)
    57  
    58  	// MethodB has a blank receiver type parameter.
    59  	func (t Type[_]) MethodB()
    60  
    61  	// MethodC has a lower-case receiver type parameter.
    62  	func (t Type[c]) MethodC()
    63  
    64  	// int16 shadows the predeclared type int16.
    65  	type int16 int
    66  
    67  

View as plain text