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

     1  // Copyright 2022 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 is tested when running "go test -run Manual"
     6  // without source arguments. Use for one-off debugging.
     7  
     8  package p
     9  
    10  import "fmt"
    11  
    12  type F[A, B any] int
    13  
    14  func G[A, B any](F[A, B]) {
    15  }
    16  
    17  func _() {
    18  	// TODO(gri) only report one error below (issue #50932)
    19  	var x F /* ERROR "not enough type arguments for type F: have 1, want 2" */ [int]
    20  	G(x /* ERROR "does not match" */)
    21  }
    22  
    23  // test case from issue
    24  // (lots of errors but doesn't crash anymore)
    25  
    26  type RC[G any, RG any] interface {
    27  	~[]RG
    28  }
    29  
    30  type RG[G any] struct{}
    31  
    32  type RSC[G any] []*RG[G]
    33  
    34  type M[Rc RC[G, RG], G any, RG any] struct {
    35  	Fn func(Rc)
    36  }
    37  
    38  type NFn[Rc RC[G, RG], G any, RG any] func(Rc)
    39  
    40  func NC[Rc RC[G, RG], G any, RG any](nFn NFn[Rc, G, RG]) {
    41  	var empty Rc
    42  	nFn(empty)
    43  }
    44  
    45  func NSG[G any](c RSC[G]) {
    46  	fmt.Println(c)
    47  }
    48  
    49  func MMD[Rc RC /* ERROR "not enough type arguments for type RC: have 1, want 2" */ [RG], RG any, G any]() M /* ERROR "not enough type arguments for type" */ [Rc, RG] {
    50  
    51  	var nFn NFn /* ERROR "not enough type arguments for type NFn: have 2, want 3" */ [Rc, RG]
    52  
    53  	var empty Rc
    54  	switch any(empty).(type) {
    55  	case BC /* ERROR "undefined: BC" */ :
    56  
    57  	case RSC[G]:
    58  		nFn = NSG /* ERROR "cannot use NSG[G]" */ [G]
    59  	}
    60  
    61  	return M /* ERROR "not enough type arguments for type M: have 2, want 3" */ [Rc, RG]{
    62  		Fn: func(rc Rc) {
    63  			NC(nFn /* ERROR "does not match" */)
    64  		},
    65  	}
    66  
    67  	return M /* ERROR "not enough type arguments for type M: have 2, want 3" */ [Rc, RG]{}
    68  }
    69  

View as plain text