Source file test/typeparam/tparam1.go

     1  // errorcheck
     2  
     3  // Copyright 2020 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  // Basic type parameter list type-checking (not syntax) errors.
     8  
     9  package tparam1
    10  
    11  // The predeclared identifier "any" may be used in place of interface{}.
    12  var _ any
    13  
    14  func _(_ any)
    15  
    16  type _[_ any] struct{}
    17  
    18  const N = 10
    19  
    20  type (
    21  	_                     []struct{}  // slice
    22  	_                     [N]struct{} // array
    23  	_[T any]              struct{}
    24  	_[T, T any]           struct{} // ERROR "T redeclared"
    25  	_[T1, T2 any, T3 any] struct{}
    26  )
    27  
    28  func _[T any]()             {}
    29  func _[T, T any]()          {} // ERROR "T redeclared"
    30  func _[T1, T2 any](x T1) T2 { panic(0) }
    31  
    32  // Type parameters are visible from opening [ to end of function.
    33  type C interface{}
    34  
    35  func _[T interface{}]()        {}
    36  func _[T C]()                  {}
    37  func _[T struct{}]()           {} // ok if #48424 is accepted
    38  func _[T interface{ m() T }]() {}
    39  func _[T1 interface{ m() T2 }, T2 interface{ m() T1 }]() {
    40  	var _ T1
    41  }
    42  
    43  // TODO(gri) expand this
    44  

View as plain text