Text file src/go/parser/testdata/resolution/typeparams.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  package resolution
     6  
     7  type List /* =@List */ [E /* =@E */ any] []E // @E
     8  
     9  type Pair /* =@Pair */ [L /* =@L */, R /* =@R */ any] struct {
    10  	Left /* =@Left */ L // @L
    11  	Right /* =@Right */ R // @R
    12  	L /* =@Lfield */ int
    13  }
    14  
    15  var _ = Pair /* @Pair */ [int, string]{}
    16  
    17  type Addable /* =@Addable */ interface {
    18  	~int64|~float64
    19  }
    20  
    21  func Add /* =@AddDecl */[T /* =@T */ Addable /* @Addable */](l /* =@l */, r /* =@r */ T /* @T */) T /* @T */ {
    22  	var t /* =@t */ T /* @T */
    23  	return l /* @l */ + r /* @r */ + t /* @t */
    24  }
    25  
    26  type Receiver /* =@Receiver */[P /* =@P */ any] struct {}
    27  
    28  type RP /* =@RP1 */ struct{}
    29  
    30  // TODO(rFindley): make a decision on how/whether to resolve identifiers that
    31  // refer to receiver type parameters, as is the case for the 'P' result
    32  // parameter below.
    33  //
    34  // For now, we ensure that types are not incorrectly resolved when receiver
    35  // type parameters are in scope.
    36  func (r /* =@recv */ Receiver /* @Receiver */ [RP]) m(RP) RP {}
    37  
    38  func f /* =@f */[T1 /* =@T1 */ interface{~[]T2 /* @T2 */}, T2 /* =@T2 */ any](
    39    x /* =@x */ T1 /* @T1 */, T1 /* =@T1_duplicate */ y,  // Note that this is a bug:
    40                                                          // the duplicate T1 should
    41  							// not be allowed.
    42    ){
    43    // Note that duplicate short var declarations resolve to their alt declaration.
    44    x /* @x */ := 0
    45    y /* =@y */ := 0
    46    T1 /* @T1 */ := 0
    47    var t1var /* =@t1var */ T1 /* @T1 */
    48  }
    49  
    50  // From go.dev/issue/39634
    51  func(*ph1[e, e])h(d)
    52  

View as plain text