Text file src/cmd/compile/internal/syntax/testdata/go2/smoketest.go2

     1  // Copyright 2020 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // This file contains basic generic code snippets.
     6  
     7  package p
     8  
     9  // type parameter lists
    10  type B[P any] struct{}
    11  type _[P interface{}] struct{}
    12  type _[P B] struct{}
    13  type _[P B[P]] struct{}
    14  
    15  type _[A, B, C any] struct{}
    16  type _[A, B, C B] struct{}
    17  type _[A, B, C B[A, B, C]] struct{}
    18  type _[A1, A2 B1, A3 B2, A4, A5, A6 B3] struct{}
    19  
    20  type _[A interface{}] struct{}
    21  type _[A, B interface{ m() }] struct{}
    22  
    23  type _[A, B, C any] struct{}
    24  
    25  // in functions
    26  func _[P any]()
    27  func _[P interface{}]()
    28  func _[P B]()
    29  func _[P B[P]]()
    30  
    31  // in methods
    32  func (T) _[P any]()
    33  func (T) _[P interface{}]()
    34  func (T) _[P B]()
    35  func (T) _[P B[P]]()
    36  
    37  // type instantiations
    38  type _ T[int]
    39  
    40  // in expressions
    41  var _ = T[int]{}
    42  
    43  // in embedded types
    44  type _ struct{ T[int] }
    45  
    46  // interfaces
    47  type _ interface{
    48  	m()
    49  	~int
    50  }
    51  
    52  type _ interface{
    53  	~int | ~float | ~string
    54  	~complex128
    55  	underlying(underlying underlying) underlying
    56  }
    57  
    58  type _ interface{
    59  	T
    60  	T[int]
    61  }
    62  
    63  // tricky cases
    64  func _(T[P], T[P1, P2])
    65  func _(a [N]T)
    66  
    67  type _ struct{
    68  	T[P]
    69  	T[P1, P2]
    70  	f [N]
    71  }
    72  type _ interface{
    73  	m()
    74  
    75  	// generic methods - disabled for now
    76  	// m[] /* ERROR empty type parameter list */ ()
    77  	// m[ /* ERROR cannot have type parameters */ P any](P)
    78  
    79  	// instantiated types
    80  	// T[] /* ERROR empty type argument list */
    81  	T[P]
    82  	T[P1, P2]
    83  }
    84  

View as plain text