...

Source file src/cmd/compile/internal/syntax/testdata/smoketest.go

Documentation: cmd/compile/internal/syntax/testdata

     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  // type instantiations
    32  type _ T[int]
    33  
    34  // in expressions
    35  var _ = T[int]{}
    36  
    37  // in embedded types
    38  type _ struct{ T[int] }
    39  
    40  // interfaces
    41  type _ interface {
    42  	m()
    43  	~int
    44  }
    45  
    46  type _ interface {
    47  	~int | ~float | ~string
    48  	~complex128
    49  	underlying(underlying underlying) underlying
    50  }
    51  
    52  type _ interface {
    53  	T
    54  	T[int]
    55  }
    56  
    57  // tricky cases
    58  func _(T[P], T[P1, P2])
    59  func _(a [N]T)
    60  
    61  type _ struct {
    62  	T[P]
    63  	T[P1, P2]
    64  	f[N]
    65  }
    66  type _ interface {
    67  	m()
    68  
    69  	// instantiated types
    70  	T[ /* ERROR empty type argument list */ ]
    71  	T[P]
    72  	T[P1, P2]
    73  }
    74  

View as plain text