Text file src/go/types/testdata/check/typeinference.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 typeInference
     6  
     7  // As of issue #51527, type-type inference has been disabled.
     8  
     9  // basic inference
    10  type Tb[P ~*Q, Q any] int
    11  func _() {
    12  	var x Tb /* ERROR got 1 arguments */ [*int]
    13  	var y Tb[*int, int]
    14  	x = y /* ERROR cannot use y .* in assignment */
    15  	_ = x
    16  }
    17  
    18  // recursive inference
    19  type Tr[A any, B *C, C *D, D *A] int
    20  func _() {
    21  	var x Tr /* ERROR got 1 arguments */ [string]
    22  	var y Tr[string, ***string, **string, *string]
    23  	var z Tr[int, ***int, **int, *int]
    24  	x = y /* ERROR cannot use y .* in assignment */
    25  	x = z // ERROR cannot use z .* as Tr
    26  	_ = x
    27  }
    28  
    29  // other patterns of inference
    30  type To0[A any, B []A] int
    31  type To1[A any, B struct{a A}] int
    32  type To2[A any, B [][]A] int
    33  type To3[A any, B [3]*A] int
    34  type To4[A any, B any, C struct{a A; b B}] int
    35  func _() {
    36  	var _ To0 /* ERROR got 1 arguments */ [int]
    37  	var _ To1 /* ERROR got 1 arguments */ [int]
    38  	var _ To2 /* ERROR got 1 arguments */ [int]
    39  	var _ To3 /* ERROR got 1 arguments */ [int]
    40  	var _ To4 /* ERROR got 2 arguments */ [int, string]
    41  }
    42  
    43  // failed inference
    44  type Tf0[A, B any] int
    45  type Tf1[A any, B ~struct{a A; c C}, C any] int
    46  func _() {
    47  	var _ Tf0 /* ERROR got 1 arguments but 2 type parameters */ [int]
    48  	var _ Tf1 /* ERROR got 1 arguments but 3 type parameters */ [int]
    49  }
    50  

View as plain text