...

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

Documentation: cmd/compile/internal/syntax/testdata

     1  // Copyright 2021 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 test cases for typeset-only constraint elements.
     6  
     7  package p
     8  
     9  type (
    10          _[_ t] t
    11          _[_ ~t] t
    12          _[_ t|t] t
    13          _[_ ~t|t] t
    14          _[_ t|~t] t
    15          _[_ ~t|~t] t
    16  
    17          _[_ t, _, _ t|t] t
    18          _[_ t, _, _ ~t|t] t
    19          _[_ t, _, _ t|~t] t
    20          _[_ t, _, _ ~t|~t] t
    21  
    22          _[_ t.t] t
    23          _[_ ~t.t] t
    24          _[_ t.t|t.t] t
    25          _[_ ~t.t|t.t] t
    26          _[_ t.t|~t.t] t
    27          _[_ ~t.t|~t.t] t
    28  
    29          _[_ t, _, _ t.t|t.t] t
    30          _[_ t, _, _ ~t.t|t.t] t
    31          _[_ t, _, _ t.t|~t.t] t
    32          _[_ t, _, _ ~t.t|~t.t] t
    33  
    34          _[_ struct{}] t
    35          _[_ ~struct{}] t
    36  
    37          _[_ struct{}|t] t
    38          _[_ ~struct{}|t] t
    39          _[_ struct{}|~t] t
    40          _[_ ~struct{}|~t] t
    41  
    42          _[_ t|struct{}] t
    43          _[_ ~t|struct{}] t
    44          _[_ t|~struct{}] t
    45          _[_ ~t|~struct{}] t
    46  
    47          // test cases for go.dev/issue/49175
    48          _[_ []t]t
    49          _[_ [1]t]t
    50          _[_ ~[]t]t
    51          _[_ ~[1]t]t
    52          t [ /* ERROR missing type parameter name */ t[0]]t
    53  )
    54  
    55  // test cases for go.dev/issue/49174
    56  func _[_ t]() {}
    57  func _[_ []t]() {}
    58  func _[_ [1]t]() {}
    59  func _[_ []t | t]() {}
    60  func _[_ [1]t | t]() {}
    61  func _[_ t | []t]() {}
    62  func _[_ []t | []t]() {}
    63  func _[_ [1]t | [1]t]() {}
    64  func _[_ t[t] | t[t]]() {}
    65  
    66  // Single-expression type parameter lists and those that don't start
    67  // with a (type parameter) name are considered array sizes.
    68  // The term must be a valid expression (it could be a type incl. a
    69  // tilde term) but the type-checker will complain.
    70  type (
    71          _[t] t
    72          _[t|t] t
    73  
    74          // These are invalid and the type-checker will complain.
    75          _[~t] t
    76          _[~t|t] t
    77          _[t|~t] t
    78          _[~t|~t] t
    79  )
    80  
    81  type (
    82          _[_ t, t /* ERROR missing type constraint */ ] t
    83          _[_ ~t, t /* ERROR missing type constraint */ ] t
    84          _[_ t, /* ERROR missing type parameter name */ ~t] t
    85          _[_ ~t, /* ERROR missing type parameter name */ ~t] t
    86  
    87          _[_ t|t, /* ERROR missing type parameter name */ t|t] t
    88          _[_ ~t|t, /* ERROR missing type parameter name */ t|t] t
    89          _[_ t|t, /* ERROR missing type parameter name */ ~t|t] t
    90          _[_ ~t|t, /* ERROR missing type parameter name */ ~t|t] t
    91  )
    92  

View as plain text