Text file src/go/parser/testdata/typeset.go2

     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  // TODO(gri) gofmt once/if gofmt supports this notation.
     7  
     8  package p
     9  
    10  type (
    11          _[_ t] t
    12          _[_ ~t] t
    13          _[_ t|t] t
    14          _[_ ~t|t] t
    15          _[_ t|~t] t
    16          _[_ ~t|~t] t
    17  
    18          _[_ t, _, _ t|t] t
    19          _[_ t, _, _ ~t|t] t
    20          _[_ t, _, _ t|~t] t
    21          _[_ t, _, _ ~t|~t] t
    22  
    23          _[_ t.t] t
    24          _[_ ~t.t] t
    25          _[_ t.t|t.t] t
    26          _[_ ~t.t|t.t] t
    27          _[_ t.t|~t.t] t
    28          _[_ ~t.t|~t.t] t
    29  
    30          _[_ t, _, _ t.t|t.t] t
    31          _[_ t, _, _ ~t.t|t.t] t
    32          _[_ t, _, _ t.t|~t.t] t
    33          _[_ t, _, _ ~t.t|~t.t] t
    34  
    35          _[_ struct{}] t
    36          _[_ ~struct{}] t
    37  
    38          _[_ struct{}|t] t
    39          _[_ ~struct{}|t] t
    40          _[_ struct{}|~t] t
    41          _[_ ~struct{}|~t] t
    42  
    43          _[_ t|struct{}] t
    44          _[_ ~t|struct{}] t
    45          _[_ t|~struct{}] t
    46          _[_ ~t|~struct{}] t
    47  )
    48  
    49  // Single-expression type parameter lists and those that don't start
    50  // with a (type parameter) name are considered array sizes.
    51  // The term must be a valid expression (it could be a type - and then
    52  // a type-checker will complain - but we don't allow ~ in the expr).
    53  // TODO(rfindley): Improve error recover here. In these cases go/parser error
    54  // recovery is worse than cmd/compile/internal/syntax, and unnecessary type
    55  // declarations had to be inserted to force synchronization.
    56  type _[t] t
    57  type _[~ /* ERROR "expected operand" */ t] t
    58  type /* ERROR "expected ']'" */ Sync int  // placeholder to synchronize the parser
    59  type _[t|t] t
    60  type _[~ /* ERROR "expected operand" */ t|t] t
    61  type /* ERROR "expected ']'" */ Sync int  // placeholder to synchronize the parser
    62  type _[t| ~ /* ERROR "expected operand" */ t] t
    63  type /* ERROR "expected ']'" */ Sync int  // placeholder to synchronize the parser
    64  type _[~ /* ERROR "expected operand" */ t|~t] t
    65  type /* ERROR "expected ']'" */ Sync int  // placeholder to synchronize the parser
    66  
    67  type _[_ t, t /* ERROR "type parameters must be named" */ ] t
    68  type _[_ ~t, t /* ERROR "type parameters must be named" */ ] t
    69  type _[_ t, ~ /* ERROR "type parameters must be named" */ t] t
    70  type _[_ ~t, ~ /* ERROR "type parameters must be named" */ t] t
    71  
    72  type _[_ t|t, t /* ERROR "type parameters must be named" */ |t] t
    73  type _[_ ~t|t, t /* ERROR "type parameters must be named" */ |t] t
    74  type _[_ t|t, ~ /* ERROR "type parameters must be named" */ t|t] t
    75  type _[_ ~t|t, ~ /* ERROR "type parameters must be named" */ t|t] t
    76  

View as plain text