...

Source file src/internal/types/testdata/fixedbugs/issue47818.go

Documentation: internal/types/testdata/fixedbugs

     1  // -lang=go1.17
     2  
     3  // Copyright 2021 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  // Parser accepts type parameters but the type checker
     8  // needs to report any operations that are not permitted
     9  // before Go 1.18.
    10  
    11  package p
    12  
    13  type T[P /* ERROR "type parameter requires go1.18 or later" */ any /* ERROR "predeclared any requires go1.18 or later" */] struct{}
    14  
    15  // for init (and main, but we're not in package main) we should only get one error
    16  func init[P /* ERROR "func init must have no type parameters" */ any /* ERROR "predeclared any requires go1.18 or later" */]() {
    17  }
    18  func main[P /* ERROR "type parameter requires go1.18 or later" */ any /* ERROR "predeclared any requires go1.18 or later" */]() {
    19  }
    20  
    21  func f[P /* ERROR "type parameter requires go1.18 or later" */ any /* ERROR "predeclared any requires go1.18 or later" */](x P) {
    22  	var _ T[ /* ERROR "type instantiation requires go1.18 or later" */ int]
    23  	var _ (T[ /* ERROR "type instantiation requires go1.18 or later" */ int])
    24  	_ = T[ /* ERROR "type instantiation requires go1.18 or later" */ int]{}
    25  	_ = T[ /* ERROR "type instantiation requires go1.18 or later" */ int](struct{}{})
    26  }
    27  
    28  func (T[ /* ERROR "type instantiation requires go1.18 or later" */ P]) g(x int) {
    29  	f[ /* ERROR "function instantiation requires go1.18 or later" */ int](0)     // explicit instantiation
    30  	(f[ /* ERROR "function instantiation requires go1.18 or later" */ int])(0)   // parentheses (different code path)
    31  	f( /* ERROR "implicit function instantiation requires go1.18 or later" */ x) // implicit instantiation
    32  }
    33  
    34  type C1 interface {
    35  	comparable // ERROR "predeclared comparable requires go1.18 or later"
    36  }
    37  
    38  type C2 interface {
    39  	comparable // ERROR "predeclared comparable requires go1.18 or later"
    40  	int        // ERROR "embedding non-interface type int requires go1.18 or later"
    41  	~ /* ERROR "embedding interface element ~int requires go1.18 or later" */ int
    42  	int /* ERROR "embedding interface element int | ~string requires go1.18 or later" */ | ~string
    43  }
    44  
    45  type _ interface {
    46  	// errors for these were reported with their declaration
    47  	C1
    48  	C2
    49  }
    50  
    51  type (
    52  	_ comparable // ERROR "predeclared comparable requires go1.18 or later"
    53  	// errors for these were reported with their declaration
    54  	_ C1
    55  	_ C2
    56  
    57  	_ = comparable // ERROR "predeclared comparable requires go1.18 or later"
    58  	// errors for these were reported with their declaration
    59  	_ = C1
    60  	_ = C2
    61  )
    62  

View as plain text