Text file src/go/doc/testdata/generics.0.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 {
    27  		// contains filtered or unexported fields
    28  	})
    29  
    30  	// Constraint is a constraint interface with two type parameters.
    31  	type Constraint[P, Q interface{ string | ~int | Type[int] }] interface {
    32  		~int | ~byte | Type[string]
    33  		M() P
    34  	}
    35  
    36  	// NewEmbeddings demonstrates how we filter the new embedded ...
    37  	type NewEmbeddings interface {
    38  		string	// should not be filtered
    39  
    40  		struct {
    41  			// contains filtered or unexported fields
    42  		}
    43  		~struct {
    44  			// contains filtered or unexported fields
    45  		}
    46  		*struct {
    47  			// contains filtered or unexported fields
    48  		}
    49  		struct {
    50  			// contains filtered or unexported fields
    51  		} | ~struct {
    52  			// contains filtered or unexported fields
    53  		}
    54  		// contains filtered or unexported methods
    55  	}
    56  
    57  	// Parameterized types should be shown.
    58  	type Type[P any] struct {
    59  		Field P
    60  	}
    61  
    62  	// Variables with an instantiated type should be shown.
    63  	var X Type[int]
    64  
    65  	// Constructors for parameterized types should be shown.
    66  	func Constructor[lowerCase any]() Type[lowerCase]
    67  
    68  	// MethodA uses a different name for its receiver type parameter.
    69  	func (t Type[A]) MethodA(p A)
    70  
    71  	// MethodB has a blank receiver type parameter.
    72  	func (t Type[_]) MethodB()
    73  
    74  	// MethodC has a lower-case receiver type parameter.
    75  	func (t Type[c]) MethodC()
    76  
    77  

View as plain text