mirror of
https://github.com/golang/go
synced 2024-11-27 00:51:26 -07:00
cmd/compile/internal/types2: use go/types/testdata/fixedbugs tests
Since the fixedbugs tests are now identical between the two type checkers, remove the local copy of the fixedbugs tests and (for now) use the tests in go/types/testdata/fixedbugs instead. Eventually we may decide to move all tests out of the type checker directories and place them in a shared space (e.g. internal/types/testdata). For #54511. Change-Id: I451c20c784710c36fa50b1d24ac97af554c572af Reviewed-on: https://go-review.googlesource.com/c/go/+/426658 Auto-Submit: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@google.com> Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
9649a4119c
commit
29e360274a
@ -301,9 +301,11 @@ func TestCheck(t *testing.T) {
|
||||
DefPredeclaredTestFuncs()
|
||||
testDirFiles(t, "../../../../go/types/testdata/check", 55, false) // TODO(gri) narrow column tolerance
|
||||
}
|
||||
func TestSpec(t *testing.T) { testDirFiles(t, "../../../../go/types/testdata/spec", 0, false) }
|
||||
func TestExamples(t *testing.T) { testDirFiles(t, "../../../../go/types/testdata/examples", 45, false) } // TODO(gri) narrow column tolerance
|
||||
func TestFixedbugs(t *testing.T) { testDirFiles(t, "testdata/fixedbugs", 100, false) } // TODO(gri) narrow column tolerance
|
||||
func TestSpec(t *testing.T) { testDirFiles(t, "../../../../go/types/testdata/spec", 0, false) }
|
||||
func TestExamples(t *testing.T) { testDirFiles(t, "../../../../go/types/testdata/examples", 45, false) } // TODO(gri) narrow column tolerance
|
||||
func TestFixedbugs(t *testing.T) {
|
||||
testDirFiles(t, "../../../../go/types/testdata/fixedbugs", 100, false)
|
||||
} // TODO(gri) narrow column tolerance
|
||||
|
||||
func testDirFiles(t *testing.T, dir string, colDelta uint, manual bool) {
|
||||
testenv.MustHaveGoBuild(t)
|
||||
|
@ -1,14 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package issue20583
|
||||
|
||||
const (
|
||||
_ = 6e886451608 /* ERROR malformed constant */ /2
|
||||
_ = 6e886451608i /* ERROR malformed constant */ /2
|
||||
_ = 0 * 1e+1000000000 // ERROR malformed constant
|
||||
|
||||
x = 1e100000000
|
||||
_ = x*x*x*x*x*x* /* ERROR not representable */ x
|
||||
)
|
@ -1,14 +0,0 @@
|
||||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type T struct{}
|
||||
|
||||
func (T) m1() {}
|
||||
func (T) m2([unsafe.Sizeof(T.m1)]int) {}
|
||||
|
||||
func main() {}
|
@ -1,14 +0,0 @@
|
||||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type T struct{}
|
||||
|
||||
func (T) m2([unsafe.Sizeof(T.m1)]int) {}
|
||||
func (T) m1() {}
|
||||
|
||||
func main() {}
|
@ -1,26 +0,0 @@
|
||||
// Copyright 2022 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
// examples from the issue
|
||||
|
||||
type (
|
||||
e = f
|
||||
f = g
|
||||
g = []h
|
||||
h i
|
||||
i = j
|
||||
j = e
|
||||
)
|
||||
|
||||
type (
|
||||
e1 = []h1
|
||||
h1 e1
|
||||
)
|
||||
|
||||
type (
|
||||
P = *T
|
||||
T P
|
||||
)
|
@ -1,13 +0,0 @@
|
||||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// stand-alone test to ensure case is triggered
|
||||
|
||||
package issue26390
|
||||
|
||||
type A = T
|
||||
|
||||
func (t *T) m() *A { return t }
|
||||
|
||||
type T struct{}
|
@ -1,65 +0,0 @@
|
||||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// This file contains test cases for various forms of
|
||||
// method receiver declarations, per the spec clarification
|
||||
// https://golang.org/cl/142757.
|
||||
|
||||
package issue28251
|
||||
|
||||
// test case from issue28251
|
||||
type T struct{}
|
||||
|
||||
type T0 = *T
|
||||
|
||||
func (T0) m() {}
|
||||
|
||||
func _() { (&T{}).m() }
|
||||
|
||||
// various alternative forms
|
||||
type (
|
||||
T1 = (((T)))
|
||||
)
|
||||
|
||||
func ((*(T1))) m1() {}
|
||||
func _() { (T{}).m2() }
|
||||
func _() { (&T{}).m2() }
|
||||
|
||||
type (
|
||||
T2 = (((T3)))
|
||||
T3 = T
|
||||
)
|
||||
|
||||
func (T2) m2() {}
|
||||
func _() { (T{}).m2() }
|
||||
func _() { (&T{}).m2() }
|
||||
|
||||
type (
|
||||
T4 = ((*(T5)))
|
||||
T5 = T
|
||||
)
|
||||
|
||||
func (T4) m4() {}
|
||||
func _() { (T{}).m4 /* ERROR "cannot call pointer method m4 on T" */ () }
|
||||
func _() { (&T{}).m4() }
|
||||
|
||||
type (
|
||||
T6 = (((T7)))
|
||||
T7 = (*(T8))
|
||||
T8 = T
|
||||
)
|
||||
|
||||
func (T6) m6() {}
|
||||
func _() { (T{}).m6 /* ERROR "cannot call pointer method m6 on T" */ () }
|
||||
func _() { (&T{}).m6() }
|
||||
|
||||
type (
|
||||
T9 = *T10
|
||||
T10 = *T11
|
||||
T11 = T
|
||||
)
|
||||
|
||||
func (T9 /* ERROR invalid receiver type \*\*T */ ) m9() {}
|
||||
func _() { (T{}).m9 /* ERROR has no field or method m9 */ () }
|
||||
func _() { (&T{}).m9 /* ERROR has no field or method m9 */ () }
|
@ -1,90 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Examples adjusted to match new [T any] syntax for type parameters.
|
||||
// Also, previously permitted empty type parameter lists and instantiations
|
||||
// are now syntax errors.
|
||||
|
||||
package p
|
||||
|
||||
// crash 1
|
||||
type nt1[_ any]interface{g /* ERROR undeclared name */ }
|
||||
type ph1[e nt1[e],g(d /* ERROR undeclared name */ )]s /* ERROR undeclared name */
|
||||
func(*ph1[e,e /* ERROR redeclared */ ])h(d /* ERROR undeclared name */ )
|
||||
|
||||
// crash 2
|
||||
// Disabled: empty []'s are now syntax errors. This example leads to too many follow-on errors.
|
||||
// type Numeric2 interface{t2 /* ERROR not a type */ }
|
||||
// func t2[T Numeric2](s[]T){0 /* ERROR not a type */ []{s /* ERROR cannot index */ [0][0]}}
|
||||
|
||||
// crash 3
|
||||
type t3 *interface{ t3.p /* ERROR no field or method p */ }
|
||||
|
||||
// crash 4
|
||||
type Numeric4 interface{t4 /* ERROR not a type */ }
|
||||
func t4[T Numeric4](s[]T){if( /* ERROR non-boolean */ 0){*s /* ERROR cannot indirect */ [0]}}
|
||||
|
||||
// crash 7
|
||||
type foo7 interface { bar() }
|
||||
type x7[A any] struct{ foo7 }
|
||||
func main7() { var _ foo7 = x7[int]{} }
|
||||
|
||||
// crash 8
|
||||
type foo8[A any] interface { ~A /* ERROR cannot be a type parameter */ }
|
||||
func bar8[A foo8[A]](a A) {}
|
||||
|
||||
// crash 9
|
||||
type foo9[A any] interface { foo9 /* ERROR illegal cycle */ [A] }
|
||||
func _() { var _ = new(foo9[int]) }
|
||||
|
||||
// crash 12
|
||||
var u /* ERROR cycle */ , i [func /* ERROR used as value */ /* ERROR used as value */ (u, c /* ERROR undeclared */ /* ERROR undeclared */ ) {}(0, len /* ERROR must be called */ /* ERROR must be called */ )]c /* ERROR undeclared */ /* ERROR undeclared */
|
||||
|
||||
// crash 15
|
||||
func y15() { var a /* ERROR declared but not used */ interface{ p() } = G15[string]{} }
|
||||
type G15[X any] s /* ERROR undeclared name */
|
||||
func (G15 /* ERROR generic type .* without instantiation */ ) p()
|
||||
|
||||
// crash 16
|
||||
type Foo16[T any] r16 /* ERROR not a type */
|
||||
func r16[T any]() Foo16[Foo16[T]] { panic(0) }
|
||||
|
||||
// crash 17
|
||||
type Y17 interface{ c() }
|
||||
type Z17 interface {
|
||||
c() Y17
|
||||
Y17 /* ERROR duplicate method */
|
||||
}
|
||||
func F17[T Z17](T) {}
|
||||
|
||||
// crash 18
|
||||
type o18[T any] []func(_ o18[[]_ /* ERROR cannot use _ */ ])
|
||||
|
||||
// crash 19
|
||||
type Z19 [][[]Z19{}[0][0]]c19 /* ERROR undeclared */
|
||||
|
||||
// crash 20
|
||||
type Z20 /* ERROR illegal cycle */ interface{ Z20 }
|
||||
func F20[t Z20]() { F20(t /* ERROR invalid composite literal type */ {}) }
|
||||
|
||||
// crash 21
|
||||
type Z21 /* ERROR illegal cycle */ interface{ Z21 }
|
||||
func F21[T Z21]() { ( /* ERROR not used */ F21[Z21]) }
|
||||
|
||||
// crash 24
|
||||
type T24[P any] P // ERROR cannot use a type parameter as RHS in type declaration
|
||||
func (r T24[P]) m() { T24 /* ERROR without instantiation */ .m() }
|
||||
|
||||
// crash 25
|
||||
type T25[A any] int
|
||||
func (t T25[A]) m1() {}
|
||||
var x T25 /* ERROR without instantiation */ .m1
|
||||
|
||||
// crash 26
|
||||
type T26 = interface{ F26[ /* ERROR interface method must have no type parameters */ Z any]() }
|
||||
func F26[Z any]() T26 { return F26[] /* ERROR operand */ }
|
||||
|
||||
// crash 27
|
||||
func e27[T any]() interface{ x27 /* ERROR not a type */ } { panic(0) }
|
||||
func x27() { e27 /* ERROR cannot infer T */ () }
|
@ -1,15 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type T[_ any] struct {}
|
||||
|
||||
func (T /* ERROR instantiation */ ) m()
|
||||
|
||||
func _() {
|
||||
var x interface { m() }
|
||||
x = T[int]{}
|
||||
_ = x
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
// Embedding stand-alone type parameters is not permitted for now. Disabled.
|
||||
|
||||
/*
|
||||
import "fmt"
|
||||
|
||||
// Minimal test case.
|
||||
func _[T interface{~T}](x T) T{
|
||||
return x
|
||||
}
|
||||
|
||||
// Test case from issue.
|
||||
type constr[T any] interface {
|
||||
~T
|
||||
}
|
||||
|
||||
func Print[T constr[T]](s []T) {
|
||||
for _, v := range s {
|
||||
fmt.Print(v)
|
||||
}
|
||||
}
|
||||
|
||||
func f() {
|
||||
Print([]string{"Hello, ", "playground\n"})
|
||||
}
|
||||
*/
|
@ -1,23 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type Number1 interface {
|
||||
// embedding non-interface types is permitted
|
||||
int
|
||||
float64
|
||||
}
|
||||
|
||||
func Add1[T Number1](a, b T) T {
|
||||
return a /* ERROR not defined */ + b
|
||||
}
|
||||
|
||||
type Number2 interface {
|
||||
int | float64
|
||||
}
|
||||
|
||||
func Add2[T Number2](a, b T) T {
|
||||
return a + b
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type T0 interface{
|
||||
}
|
||||
|
||||
type T1 interface{
|
||||
~int
|
||||
}
|
||||
|
||||
type T2 interface{
|
||||
comparable
|
||||
}
|
||||
|
||||
type T3 interface {
|
||||
T0
|
||||
T1
|
||||
T2
|
||||
}
|
||||
|
||||
func _() {
|
||||
_ = T0(0)
|
||||
_ = T1 /* ERROR cannot use interface T1 in conversion */ (1)
|
||||
_ = T2 /* ERROR cannot use interface T2 in conversion */ (2)
|
||||
_ = T3 /* ERROR cannot use interface T3 in conversion */ (3)
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
// Do not report a duplicate type error for this term list.
|
||||
// (Check types after interfaces have been completed.)
|
||||
type _ interface {
|
||||
// TODO(rfindley) Once we have full type sets we can enable this again.
|
||||
// Fow now we don't permit interfaces in term lists.
|
||||
// type interface{ Error() string }, interface{ String() string }
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
// A constraint must be an interface; it cannot
|
||||
// be a type parameter, for instance.
|
||||
func _[A interface{ ~int }, B A /* ERROR cannot use a type parameter as constraint */ ]() {}
|
@ -1,16 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func f1[T1, T2 any](T1, T2, struct{a T1; b T2}) {}
|
||||
func _() {
|
||||
f1(42, string("foo"), struct /* ERROR does not match inferred type struct\{a int; b string\} */ {a, b int}{})
|
||||
}
|
||||
|
||||
// simplified test case from issue
|
||||
func f2[T any](_ []T, _ func(T)) {}
|
||||
func _() {
|
||||
f2([]string{}, func /* ERROR does not match inferred type func\(string\) */ (f []byte) {})
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type Optional[T any] struct {}
|
||||
|
||||
func (_ Optional[T]) Val() (T, bool)
|
||||
|
||||
type Box[T any] interface {
|
||||
Val() (T, bool)
|
||||
}
|
||||
|
||||
func f[V interface{}, A, B Box[V]]() {}
|
||||
|
||||
func _() {
|
||||
f[int, Optional[int], Optional[int]]()
|
||||
_ = f[int, Optional[int], Optional /* ERROR does not implement Box */ [string]]
|
||||
_ = f[int, Optional[int], Optional /* ERROR Optional.* does not implement Box.* */ [string]]
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func _[T interface{~map[string]int}](x T) {
|
||||
_ = x == nil
|
||||
}
|
||||
|
||||
// simplified test case from issue
|
||||
|
||||
type PathParamsConstraint interface {
|
||||
~map[string]string | ~[]struct{key, value string}
|
||||
}
|
||||
|
||||
type PathParams[T PathParamsConstraint] struct {
|
||||
t T
|
||||
}
|
||||
|
||||
func (pp *PathParams[T]) IsNil() bool {
|
||||
return pp.t == nil // this must succeed
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
// For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639).
|
||||
// type T[P any] P
|
||||
// type A = T // ERROR cannot use generic type
|
||||
// var x A[int]
|
||||
// var _ A
|
||||
//
|
||||
// type B = T[int]
|
||||
// var y B = x
|
||||
// var _ B /* ERROR not a generic type */ [int]
|
||||
|
||||
// test case from issue
|
||||
|
||||
type Vector[T any] []T
|
||||
type VectorAlias = Vector // ERROR cannot use generic type
|
||||
var v Vector[int]
|
@ -1,54 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
// All but E2 and E5 provide an "indirection" and break infinite expansion of a type.
|
||||
type E0[P any] []P
|
||||
type E1[P any] *P
|
||||
type E2[P any] struct{ _ P }
|
||||
type E3[P any] struct{ _ *P }
|
||||
type E5[P any] struct{ _ [10]P }
|
||||
|
||||
type T0 struct {
|
||||
_ E0[T0]
|
||||
}
|
||||
|
||||
type T0_ struct {
|
||||
E0[T0_]
|
||||
}
|
||||
|
||||
type T1 struct {
|
||||
_ E1[T1]
|
||||
}
|
||||
|
||||
type T2 /* ERROR illegal cycle */ struct {
|
||||
_ E2[T2]
|
||||
}
|
||||
|
||||
type T3 struct {
|
||||
_ E3[T3]
|
||||
}
|
||||
|
||||
type T4 /* ERROR illegal cycle */ [10]E5[T4]
|
||||
|
||||
type T5 struct {
|
||||
_ E0[E2[T5]]
|
||||
}
|
||||
|
||||
type T6 struct {
|
||||
_ E0[E2[E0[E1[E2[[10]T6]]]]]
|
||||
}
|
||||
|
||||
type T7 struct {
|
||||
_ E0[[10]E2[E0[E2[E2[T7]]]]]
|
||||
}
|
||||
|
||||
type T8 struct {
|
||||
_ E0[[]E2[E0[E2[E2[T8]]]]]
|
||||
}
|
||||
|
||||
type T9 /* ERROR illegal cycle */ [10]E2[E5[E2[T9]]]
|
||||
|
||||
type T10 [10]E2[E5[E2[func(T10)]]]
|
@ -1,9 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type T[P any] interface{
|
||||
P // ERROR term cannot be a type parameter
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type policy[K, V any] interface{}
|
||||
type LRU[K, V any] struct{}
|
||||
|
||||
func NewCache[K, V any](p policy[K, V]) {}
|
||||
|
||||
func _() {
|
||||
var lru LRU[int, string]
|
||||
NewCache[int, string](&lru)
|
||||
NewCache(& /* ERROR does not match policy\[K, V\] \(cannot infer K and V\) */ lru)
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type (
|
||||
T[_ any] struct{}
|
||||
S[_ any] struct {
|
||||
data T[*T[int]]
|
||||
}
|
||||
)
|
||||
|
||||
func _() {
|
||||
_ = S[int]{
|
||||
data: T[*T[int]]{},
|
||||
}
|
||||
}
|
||||
|
||||
// full test case from issue
|
||||
|
||||
type (
|
||||
Element[TElem any] struct{}
|
||||
|
||||
entry[K comparable] struct{}
|
||||
|
||||
Cache[K comparable] struct {
|
||||
data map[K]*Element[*entry[K]]
|
||||
}
|
||||
)
|
||||
|
||||
func _() {
|
||||
_ = Cache[int]{
|
||||
data: make(map[int](*Element[*entry[int]])),
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type A[T any] int
|
||||
|
||||
func (A[T]) m(A[T])
|
||||
|
||||
func f[P interface{m(P)}]() {}
|
||||
|
||||
func _() {
|
||||
_ = f[A[int]]
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func _() {
|
||||
NewS /* ERROR cannot infer T */ ().M()
|
||||
}
|
||||
|
||||
type S struct {}
|
||||
|
||||
func NewS[T any]() *S { panic(0) }
|
||||
|
||||
func (_ *S /* ERROR S is not a generic type */ [T]) M()
|
@ -1,17 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func _() {
|
||||
var x interface{}
|
||||
switch t := x.(type) {
|
||||
case S /* ERROR cannot use generic type */ :
|
||||
t.m()
|
||||
}
|
||||
}
|
||||
|
||||
type S[T any] struct {}
|
||||
|
||||
func (_ S[T]) m()
|
@ -1,12 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
import "unsafe"
|
||||
|
||||
func _[T any](x T) {
|
||||
_ = unsafe.Alignof(x)
|
||||
_ = unsafe.Sizeof(x)
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
// Copyright 2022 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type number interface {
|
||||
~float64 | ~int | ~int32
|
||||
float64 | ~int32
|
||||
}
|
||||
|
||||
func f[T number]() {}
|
||||
|
||||
func _() {
|
||||
_ = f[int /* ERROR int does not implement number \(int missing in float64 | ~int32\)*/]
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type T[_ any] int
|
||||
|
||||
func f[_ any]() {}
|
||||
func g[_, _ any]() {}
|
||||
|
||||
func _() {
|
||||
_ = f[T /* ERROR without instantiation */ ]
|
||||
_ = g[T /* ERROR without instantiation */ , T /* ERROR without instantiation */ ]
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
m := map[string]int{
|
||||
"a": 6,
|
||||
"b": 7,
|
||||
}
|
||||
fmt.Println(copyMap[map[string]int, string, int](m))
|
||||
}
|
||||
|
||||
type Map[K comparable, V any] interface {
|
||||
map[K] V
|
||||
}
|
||||
|
||||
func copyMap[M Map[K, V], K comparable, V any](m M) M {
|
||||
m1 := make(M)
|
||||
for k, v := range m {
|
||||
m1[k] = v
|
||||
}
|
||||
return m1
|
||||
}
|
||||
|
||||
// simpler test case from the same issue
|
||||
|
||||
type A[X comparable] interface {
|
||||
[]X
|
||||
}
|
||||
|
||||
func f[B A[X], X comparable]() B {
|
||||
return nil
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
// Test case from issue.
|
||||
|
||||
type Nat /* ERROR cycle */ interface {
|
||||
Zero|Succ
|
||||
}
|
||||
|
||||
type Zero struct{}
|
||||
type Succ struct{
|
||||
Nat // Nat contains type constraints but is invalid, so no error
|
||||
}
|
||||
|
||||
// Struct tests.
|
||||
|
||||
type I1 interface {
|
||||
comparable
|
||||
}
|
||||
|
||||
type I2 interface {
|
||||
~int
|
||||
}
|
||||
|
||||
type I3 interface {
|
||||
I1
|
||||
I2
|
||||
}
|
||||
|
||||
type _ struct {
|
||||
f I1 // ERROR interface is .* comparable
|
||||
}
|
||||
|
||||
type _ struct {
|
||||
comparable // ERROR interface is .* comparable
|
||||
}
|
||||
|
||||
type _ struct{
|
||||
I1 // ERROR interface is .* comparable
|
||||
}
|
||||
|
||||
type _ struct{
|
||||
I2 // ERROR interface contains type constraints
|
||||
}
|
||||
|
||||
type _ struct{
|
||||
I3 // ERROR interface contains type constraints
|
||||
}
|
||||
|
||||
// General composite types.
|
||||
|
||||
type (
|
||||
_ [10]I1 // ERROR interface is .* comparable
|
||||
_ [10]I2 // ERROR interface contains type constraints
|
||||
|
||||
_ []I1 // ERROR interface is .* comparable
|
||||
_ []I2 // ERROR interface contains type constraints
|
||||
|
||||
_ *I3 // ERROR interface contains type constraints
|
||||
_ map[I1 /* ERROR interface is .* comparable */ ]I2 // ERROR interface contains type constraints
|
||||
_ chan I3 // ERROR interface contains type constraints
|
||||
_ func(I1 /* ERROR interface is .* comparable */ )
|
||||
_ func() I2 // ERROR interface contains type constraints
|
||||
)
|
||||
|
||||
// Other cases.
|
||||
|
||||
var _ = [...]I3 /* ERROR interface contains type constraints */ {}
|
||||
|
||||
func _(x interface{}) {
|
||||
_ = x.(I3 /* ERROR interface contains type constraints */ )
|
||||
}
|
||||
|
||||
type T1[_ any] struct{}
|
||||
type T3[_, _, _ any] struct{}
|
||||
var _ T1[I2 /* ERROR interface contains type constraints */ ]
|
||||
var _ T3[int, I2 /* ERROR interface contains type constraints */ , float32]
|
||||
|
||||
func f1[_ any]() int { panic(0) }
|
||||
var _ = f1[I2 /* ERROR interface contains type constraints */ ]()
|
||||
func f3[_, _, _ any]() int { panic(0) }
|
||||
var _ = f3[int, I2 /* ERROR interface contains type constraints */ , float32]()
|
||||
|
||||
func _(x interface{}) {
|
||||
switch x.(type) {
|
||||
case I2 /* ERROR interface contains type constraints */ :
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package issue42695
|
||||
|
||||
const _ = 6e5518446744 // ERROR malformed constant
|
||||
const _ uint8 = 6e5518446744 // ERROR malformed constant
|
||||
|
||||
var _ = 6e5518446744 // ERROR malformed constant
|
||||
var _ uint8 = 6e5518446744 // ERROR malformed constant
|
||||
|
||||
func f(x int) int {
|
||||
return x + 6e5518446744 // ERROR malformed constant
|
||||
}
|
||||
|
||||
var _ = f(6e5518446744 /* ERROR malformed constant */ )
|
@ -1,33 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func _[T any](x interface{}){
|
||||
switch x.(type) {
|
||||
case T: // ok to use a type parameter
|
||||
case int:
|
||||
}
|
||||
|
||||
switch x.(type) {
|
||||
case T:
|
||||
case T /* ERROR duplicate case */ :
|
||||
}
|
||||
}
|
||||
|
||||
type constraint interface {
|
||||
~int
|
||||
}
|
||||
|
||||
func _[T constraint](x interface{}){
|
||||
switch x.(type) {
|
||||
case T: // ok to use a type parameter even if type set contains int
|
||||
case int:
|
||||
}
|
||||
}
|
||||
|
||||
func _(x constraint /* ERROR contains type constraints */ ) {
|
||||
switch x.(type) { // no need to report another error
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
// Copyright 2022 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type (
|
||||
T1 interface{ comparable }
|
||||
T2 interface{ int }
|
||||
)
|
||||
|
||||
var (
|
||||
_ comparable // ERROR cannot use type comparable outside a type constraint: interface is \(or embeds\) comparable
|
||||
_ T1 // ERROR cannot use type T1 outside a type constraint: interface is \(or embeds\) comparable
|
||||
_ T2 // ERROR cannot use type T2 outside a type constraint: interface contains type constraints
|
||||
)
|
@ -1,8 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Check that there is only one error (no follow-on errors).
|
||||
|
||||
package p
|
||||
var _ = [ ... /* ERROR invalid use of \[...\] array */ ]byte("foo")
|
@ -1,31 +0,0 @@
|
||||
// Copyright 2022 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
// simplified example
|
||||
func f[T ~func(T)](a, b T) {}
|
||||
|
||||
type F func(F)
|
||||
|
||||
func _() {
|
||||
var i F
|
||||
var j func(F)
|
||||
|
||||
f(i, j)
|
||||
f(j, i)
|
||||
}
|
||||
|
||||
// example from issue
|
||||
func g[T interface{ Equal(T) bool }](a, b T) {}
|
||||
|
||||
type I interface{ Equal(I) bool }
|
||||
|
||||
func _() {
|
||||
var i I
|
||||
var j interface{ Equal(I) bool }
|
||||
|
||||
g(i, j)
|
||||
g(j, i)
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func _() {
|
||||
a, b, b /* ERROR b repeated on left side of := */ := 1, 2, 3
|
||||
_ = a
|
||||
_ = b
|
||||
}
|
||||
|
||||
func _() {
|
||||
a, _, _ := 1, 2, 3 // multiple _'s ok
|
||||
_ = a
|
||||
}
|
||||
|
||||
func _() {
|
||||
var b int
|
||||
a, b, b /* ERROR b repeated on left side of := */ := 1, 2, 3
|
||||
_ = a
|
||||
_ = b
|
||||
}
|
||||
|
||||
func _() {
|
||||
var a []int
|
||||
a /* ERROR non-name .* on left side of := */ [0], b := 1, 2
|
||||
_ = a
|
||||
_ = b
|
||||
}
|
||||
|
||||
func _() {
|
||||
var a int
|
||||
a, a /* ERROR a repeated on left side of := */ := 1, 2
|
||||
_ = a
|
||||
}
|
||||
|
||||
func _() {
|
||||
var a, b int
|
||||
a, b := /* ERROR no new variables on left side of := */ 1, 2
|
||||
_ = a
|
||||
_ = b
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
// Copyright 2022 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Ensure there is no "imported but not used" error
|
||||
// if a package wasn't imported in the first place.
|
||||
|
||||
package p
|
||||
|
||||
import . "/foo" // ERROR could not import \/foo
|
@ -1,43 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type P *struct{}
|
||||
|
||||
func _() {
|
||||
// want an error even if the switch is empty
|
||||
var a struct{ _ func() }
|
||||
switch a /* ERROR cannot switch on a */ {
|
||||
}
|
||||
|
||||
switch a /* ERROR cannot switch on a */ {
|
||||
case a: // no follow-on error here
|
||||
}
|
||||
|
||||
// this is ok because f can be compared to nil
|
||||
var f func()
|
||||
switch f {
|
||||
}
|
||||
|
||||
switch f {
|
||||
case nil:
|
||||
}
|
||||
|
||||
switch (func())(nil) {
|
||||
case nil:
|
||||
}
|
||||
|
||||
switch (func())(nil) {
|
||||
case f /* ERROR invalid case f in switch on .* \(func can only be compared to nil\) */ :
|
||||
}
|
||||
|
||||
switch nil /* ERROR use of untyped nil in switch expression */ {
|
||||
}
|
||||
|
||||
// this is ok
|
||||
switch P(nil) {
|
||||
case P(nil):
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
var _ = int(0 /* ERROR invalid use of \.\.\. in conversion to int */ ...)
|
||||
|
||||
// test case from issue
|
||||
|
||||
type M []string
|
||||
|
||||
var (
|
||||
x = []string{"a", "b"}
|
||||
_ = M(x /* ERROR invalid use of \.\.\. in conversion to M */ ...)
|
||||
)
|
@ -1,8 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
var _ = new(- /* ERROR not a type */ 1)
|
||||
var _ = new(1 /* ERROR not a type */ + 1)
|
@ -1,30 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// The errors below are produced by the parser, but we check
|
||||
// them here for consistency with the types2 tests.
|
||||
|
||||
package p
|
||||
|
||||
import ; // ERROR missing import path
|
||||
import
|
||||
var /* ERROR missing import path */ _ int
|
||||
import .; // ERROR missing import path
|
||||
import 'x' // ERROR import path must be a string
|
||||
var _ int
|
||||
import /* ERROR imports must appear before other declarations */ _ "math"
|
||||
|
||||
// Don't repeat previous error for each immediately following import ...
|
||||
import ()
|
||||
import (.) // ERROR missing import path
|
||||
import (
|
||||
"fmt"
|
||||
.
|
||||
) // ERROR missing import path
|
||||
|
||||
// ... but remind with error again if we start a new import section after
|
||||
// other declarations
|
||||
var _ = fmt.Println
|
||||
import /* ERROR imports must appear before other declarations */ _ "math"
|
||||
import _ "math"
|
@ -1,16 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
const L = 10
|
||||
|
||||
type (
|
||||
_ [L]struct{}
|
||||
_ [A /* ERROR undeclared name A for array length */ ]struct{}
|
||||
_ [B /* ERROR invalid array length B */ ]struct{}
|
||||
_[A any] struct{}
|
||||
|
||||
B int
|
||||
)
|
@ -1,58 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type C0 interface{ int }
|
||||
type C1 interface{ chan int }
|
||||
type C2 interface{ chan int | <-chan int }
|
||||
type C3 interface{ chan int | chan float32 }
|
||||
type C4 interface{ chan int | chan<- int }
|
||||
type C5[T any] interface{ ~chan T | <-chan T }
|
||||
|
||||
func _[T any](ch T) {
|
||||
<-ch // ERROR cannot receive from ch .* no core type
|
||||
}
|
||||
|
||||
func _[T C0](ch T) {
|
||||
<-ch // ERROR cannot receive from non-channel ch
|
||||
}
|
||||
|
||||
func _[T C1](ch T) {
|
||||
<-ch
|
||||
}
|
||||
|
||||
func _[T C2](ch T) {
|
||||
<-ch
|
||||
}
|
||||
|
||||
func _[T C3](ch T) {
|
||||
<-ch // ERROR cannot receive from ch .* no core type
|
||||
}
|
||||
|
||||
func _[T C4](ch T) {
|
||||
<-ch // ERROR cannot receive from send-only channel
|
||||
}
|
||||
|
||||
func _[T C5[X], X any](ch T, x X) {
|
||||
x = <-ch
|
||||
}
|
||||
|
||||
// test case from issue, slightly modified
|
||||
type RecvChan[T any] interface {
|
||||
~chan T | ~<-chan T
|
||||
}
|
||||
|
||||
func _[T any, C RecvChan[T]](ch C) T {
|
||||
return <-ch
|
||||
}
|
||||
|
||||
func f[T any, C interface{ chan T }](ch C) T {
|
||||
return <-ch
|
||||
}
|
||||
|
||||
func _(ch chan int) {
|
||||
var x int = f(ch) // test constraint type inference for this case
|
||||
_ = x
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package P
|
||||
|
||||
type A1[T any] struct{}
|
||||
|
||||
func (*A1[T]) m1(T) {}
|
||||
|
||||
type A2[T any] interface {
|
||||
m2(T)
|
||||
}
|
||||
|
||||
type B1[T any] struct {
|
||||
filler int
|
||||
*A1[T]
|
||||
A2[T]
|
||||
}
|
||||
|
||||
type B2[T any] interface {
|
||||
A2[T]
|
||||
}
|
||||
|
||||
type C[T any] struct {
|
||||
filler1 int
|
||||
filler2 int
|
||||
B1[T]
|
||||
}
|
||||
|
||||
type D[T any] struct {
|
||||
filler1 int
|
||||
filler2 int
|
||||
filler3 int
|
||||
C[T]
|
||||
}
|
||||
|
||||
func _() {
|
||||
// calling embedded methods
|
||||
var b1 B1[string]
|
||||
|
||||
b1.A1.m1("")
|
||||
b1.m1("")
|
||||
|
||||
b1.A2.m2("")
|
||||
b1.m2("")
|
||||
|
||||
var b2 B2[string]
|
||||
b2.m2("")
|
||||
|
||||
// a deeper nesting
|
||||
var d D[string]
|
||||
d.m1("")
|
||||
d.m2("")
|
||||
|
||||
// calling method expressions
|
||||
m1x := B1[string].m1
|
||||
m1x(b1, "")
|
||||
m2x := B2[string].m2
|
||||
m2x(b2, "")
|
||||
|
||||
// calling method values
|
||||
m1v := b1.m1
|
||||
m1v("")
|
||||
m2v := b1.m2
|
||||
m2v("")
|
||||
b2v := b2.m2
|
||||
b2v("")
|
||||
}
|
||||
|
||||
// actual test case from issue
|
||||
|
||||
type A[T any] struct{}
|
||||
|
||||
func (*A[T]) f(T) {}
|
||||
|
||||
type B[T any] struct{ A[T] }
|
||||
|
||||
func _() {
|
||||
var b B[string]
|
||||
b.A.f("")
|
||||
b.f("")
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
func Map[F, T any](s []F, f func(F) T) []T { return nil }
|
||||
|
||||
func Reduce[Elem1, Elem2 any](s []Elem1, initializer Elem2, f func(Elem2, Elem1) Elem2) Elem2 { var x Elem2; return x }
|
||||
|
||||
func main() {
|
||||
var s []int
|
||||
var f1 func(int) float64
|
||||
var f2 func(float64, int) float64
|
||||
_ = Map[int](s, f1)
|
||||
_ = Map(s, f1)
|
||||
_ = Reduce[int](s, 0, f2)
|
||||
_ = Reduce(s, 0, f2)
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
// Copyright 2022 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
var s uint
|
||||
var _ = string(1 /* ERROR shifted operand 1 .* must be integer */ << s)
|
@ -1,13 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func f[F interface{*Q}, G interface{*R}, Q, R any](q Q, r R) {}
|
||||
|
||||
func _() {
|
||||
f[*float64, *int](1, 2)
|
||||
f[*float64](1, 2)
|
||||
f(1, 2)
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type Builder /* ERROR illegal cycle */ [T interface{ struct{ Builder[T] } }] struct{}
|
||||
type myBuilder struct {
|
||||
Builder[myBuilder]
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
some /* ERROR "undeclared name" */ [int, int]()
|
||||
}
|
||||
|
||||
type N[T any] struct{}
|
||||
|
||||
var _ N [] // ERROR expected type argument list
|
||||
|
||||
type I interface {
|
||||
~[]int
|
||||
}
|
||||
|
||||
func _[T I](i, j int) {
|
||||
var m map[int]int
|
||||
_ = m[i, j /* ERROR "more than one index" */ ]
|
||||
|
||||
var a [3]int
|
||||
_ = a[i, j /* ERROR "more than one index" */ ]
|
||||
|
||||
var s []int
|
||||
_ = s[i, j /* ERROR "more than one index" */ ]
|
||||
|
||||
var t T
|
||||
_ = t[i, j /* ERROR "more than one index" */ ]
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package P
|
||||
|
||||
// For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639).
|
||||
// // It is not permitted to declare a local type whose underlying
|
||||
// // type is a type parameters not declared by that type declaration.
|
||||
// func _[T any]() {
|
||||
// type _ T // ERROR cannot use function type parameter T as RHS in type declaration
|
||||
// type _ [_ any] T // ERROR cannot use function type parameter T as RHS in type declaration
|
||||
// }
|
@ -1,17 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func f1[T any, C chan T | <-chan T](ch C) {}
|
||||
|
||||
func _(ch chan int) { f1(ch) }
|
||||
func _(ch <-chan int) { f1(ch) }
|
||||
func _(ch chan<- int) { f1 /* ERROR chan<- int does not implement chan int\|<-chan int */ (ch) }
|
||||
|
||||
func f2[T any, C chan T | chan<- T](ch C) {}
|
||||
|
||||
func _(ch chan int) { f2(ch) }
|
||||
func _(ch <-chan int) { f2 /* ERROR <-chan int does not implement chan int\|chan<- int */ (ch) }
|
||||
func _(ch chan<- int) { f2(ch) }
|
@ -1,13 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package issue45985
|
||||
|
||||
func app[S interface{ ~[]T }, T any](s S, e T) S {
|
||||
return append(s, e)
|
||||
}
|
||||
|
||||
func _() {
|
||||
_ = app/* ERROR "S does not match" */[int]
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
// -lang=go1.17
|
||||
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// The predeclared type comparable is not visible before Go 1.18.
|
||||
|
||||
package p
|
||||
|
||||
type _ comparable // ERROR predeclared comparable
|
@ -1,26 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package issue46275
|
||||
|
||||
type N[T any] struct {
|
||||
*N[T]
|
||||
t T
|
||||
}
|
||||
|
||||
func (n *N[T]) Elem() T {
|
||||
return n.t
|
||||
}
|
||||
|
||||
type I interface {
|
||||
Elem() string
|
||||
}
|
||||
|
||||
func _() {
|
||||
var n1 *N[string]
|
||||
var _ I = n1
|
||||
type NS N[string]
|
||||
var n2 *NS
|
||||
var _ I = n2
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package issue46403
|
||||
|
||||
func _() {
|
||||
// a should be used, despite the parser error below.
|
||||
var a []int
|
||||
var _ = a[] // ERROR expected operand
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package issue46404
|
||||
|
||||
// TODO(gri) re-enable this test with matching errors
|
||||
// between go/types and types2
|
||||
// Check that we don't type check t[_] as an instantiation.
|
||||
// type t [t /* type parameters must be named */ /* not a generic type */ [_]]_ // cannot use
|
@ -1,20 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
// test case 1
|
||||
type T /* ERROR illegal cycle */ [U interface{ M() T[U] }] int
|
||||
|
||||
type X int
|
||||
|
||||
func (X) M() T[X] { return 0 }
|
||||
|
||||
// test case 2
|
||||
type A /* ERROR illegal cycle */ [T interface{ A[T] }] interface{}
|
||||
|
||||
// test case 3
|
||||
type A2 /* ERROR illegal cycle */ [U interface{ A2[U] }] interface{ M() A2[U] }
|
||||
|
||||
type I interface{ A2[I]; M() A2[I] }
|
@ -1,28 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type T1 struct{}
|
||||
func (t T1) m(int) {}
|
||||
var f1 func(T1)
|
||||
|
||||
type T2 struct{}
|
||||
func (t T2) m(x int) {}
|
||||
var f2 func(T2)
|
||||
|
||||
type T3 struct{}
|
||||
func (T3) m(int) {}
|
||||
var f3 func(T3)
|
||||
|
||||
type T4 struct{}
|
||||
func (T4) m(x int) {}
|
||||
var f4 func(T4)
|
||||
|
||||
func _() {
|
||||
f1 = T1 /* ERROR func\(T1, int\) */ .m
|
||||
f2 = T2 /* ERROR func\(t T2, x int\) */ .m
|
||||
f3 = T3 /* ERROR func\(T3, int\) */ .m
|
||||
f4 = T4 /* ERROR func\(_ T4, x int\) */ .m
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type Mer interface { M() }
|
||||
|
||||
func F[T Mer](p *T) {
|
||||
p.M /* ERROR p\.M undefined */ ()
|
||||
}
|
||||
|
||||
type MyMer int
|
||||
|
||||
func (MyMer) M() {}
|
||||
|
||||
func _() {
|
||||
F(new(MyMer))
|
||||
F[Mer](nil)
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type C0 interface{ int }
|
||||
type C1 interface{ chan int }
|
||||
type C2 interface{ chan int | <-chan int }
|
||||
type C3 interface{ chan int | chan float32 }
|
||||
type C4 interface{ chan int | chan<- int }
|
||||
type C5[T any] interface{ ~chan T | chan<- T }
|
||||
|
||||
func _[T any](ch T) {
|
||||
ch <- /* ERROR cannot send to ch .* no core type */ 0
|
||||
}
|
||||
|
||||
func _[T C0](ch T) {
|
||||
ch <- /* ERROR cannot send to non-channel */ 0
|
||||
}
|
||||
|
||||
func _[T C1](ch T) {
|
||||
ch <- 0
|
||||
}
|
||||
|
||||
func _[T C2](ch T) {
|
||||
ch <-/* ERROR cannot send to receive-only channel */ 0
|
||||
}
|
||||
|
||||
func _[T C3](ch T) {
|
||||
ch <- /* ERROR cannot send to ch .* no core type */ 0
|
||||
}
|
||||
|
||||
func _[T C4](ch T) {
|
||||
ch <- 0
|
||||
}
|
||||
|
||||
func _[T C5[X], X any](ch T, x X) {
|
||||
ch <- x
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Embedding of stand-alone type parameters is not permitted.
|
||||
|
||||
package p
|
||||
|
||||
type (
|
||||
_[P any] interface{ *P | []P | chan P | map[string]P }
|
||||
_[P any] interface{ P /* ERROR term cannot be a type parameter */ }
|
||||
_[P any] interface{ ~P /* ERROR type in term ~P cannot be a type parameter */ }
|
||||
_[P any] interface{ int | P /* ERROR term cannot be a type parameter */ }
|
||||
_[P any] interface{ int | ~P /* ERROR type in term ~P cannot be a type parameter */ }
|
||||
)
|
||||
|
||||
func _[P any]() {
|
||||
type (
|
||||
_[P any] interface{ *P | []P | chan P | map[string]P }
|
||||
_[P any] interface{ P /* ERROR term cannot be a type parameter */ }
|
||||
_[P any] interface{ ~P /* ERROR type in term ~P cannot be a type parameter */ }
|
||||
_[P any] interface{ int | P /* ERROR term cannot be a type parameter */ }
|
||||
_[P any] interface{ int | ~P /* ERROR type in term ~P cannot be a type parameter */ }
|
||||
|
||||
_ interface{ *P | []P | chan P | map[string]P }
|
||||
_ interface{ P /* ERROR term cannot be a type parameter */ }
|
||||
_ interface{ ~P /* ERROR type in term ~P cannot be a type parameter */ }
|
||||
_ interface{ int | P /* ERROR term cannot be a type parameter */ }
|
||||
_ interface{ int | ~P /* ERROR type in term ~P cannot be a type parameter */ }
|
||||
)
|
||||
}
|
||||
|
||||
func _[P any, Q interface{ *P | []P | chan P | map[string]P }]() {}
|
||||
func _[P any, Q interface{ P /* ERROR term cannot be a type parameter */ }]() {}
|
||||
func _[P any, Q interface{ ~P /* ERROR type in term ~P cannot be a type parameter */ }]() {}
|
||||
func _[P any, Q interface{ int | P /* ERROR term cannot be a type parameter */ }]() {}
|
||||
func _[P any, Q interface{ int | ~P /* ERROR type in term ~P cannot be a type parameter */ }]() {}
|
@ -1,26 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func f[_ comparable]() {}
|
||||
func g[_ interface{interface{comparable; ~int|~string}}]() {}
|
||||
|
||||
func _[P comparable,
|
||||
Q interface{ comparable; ~int|~string },
|
||||
R any, // not comparable
|
||||
S interface{ comparable; ~func() }, // not comparable
|
||||
]() {
|
||||
_ = f[int]
|
||||
_ = f[P]
|
||||
_ = f[Q]
|
||||
_ = f[func /* ERROR does not implement comparable */ ()]
|
||||
_ = f[R /* ERROR R does not implement comparable */ ]
|
||||
|
||||
_ = g[int]
|
||||
_ = g[P /* ERROR P does not implement interface{interface{comparable; ~int\|~string} */ ]
|
||||
_ = g[Q]
|
||||
_ = g[func /* ERROR func\(\) does not implement interface{interface{comparable; ~int\|~string}} */ ()]
|
||||
_ = g[R /* ERROR R does not implement interface{interface{comparable; ~int\|~string} */ ]
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
// For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639).
|
||||
// type T1[P any] P
|
||||
//
|
||||
// func (T1[_]) m() {}
|
||||
//
|
||||
// func _[P any](x *T1[P]) {
|
||||
// // x.m exists because x is of type *T1 where T1 is a defined type
|
||||
// // (even though under(T1) is a type parameter)
|
||||
// x.m()
|
||||
// }
|
||||
|
||||
|
||||
func _[P interface{ m() }](x P) {
|
||||
x.m()
|
||||
// (&x).m doesn't exist because &x is of type *P
|
||||
// and pointers to type parameters don't have methods
|
||||
(&x).m /* ERROR type \*P is pointer to type parameter, not type parameter */ ()
|
||||
}
|
||||
|
||||
|
||||
type T2 interface{ m() }
|
||||
|
||||
func _(x *T2) {
|
||||
// x.m doesn't exists because x is of type *T2
|
||||
// and pointers to interfaces don't have methods
|
||||
x.m /* ERROR type \*T2 is pointer to interface, not interface */()
|
||||
}
|
||||
|
||||
// Test case 1 from issue
|
||||
|
||||
type Fooer1[t any] interface {
|
||||
Foo(Barer[t])
|
||||
}
|
||||
type Barer[t any] interface {
|
||||
Bar(t)
|
||||
}
|
||||
|
||||
// For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639).
|
||||
// type Foo1[t any] t
|
||||
// type Bar[t any] t
|
||||
//
|
||||
// func (l Foo1[t]) Foo(v Barer[t]) { v.Bar(t(l)) }
|
||||
// func (b *Bar[t]) Bar(l t) { *b = Bar[t](l) }
|
||||
//
|
||||
// func _[t any](f Fooer1[t]) t {
|
||||
// var b Bar[t]
|
||||
// f.Foo(&b)
|
||||
// return t(b)
|
||||
// }
|
||||
|
||||
// Test case 2 from issue
|
||||
|
||||
// For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639).
|
||||
// type Fooer2[t any] interface {
|
||||
// Foo()
|
||||
// }
|
||||
//
|
||||
// type Foo2[t any] t
|
||||
//
|
||||
// func (f *Foo2[t]) Foo() {}
|
||||
//
|
||||
// func _[t any](v t) {
|
||||
// var f = Foo2[t](v)
|
||||
// _ = Fooer2[t](&f)
|
||||
// }
|
@ -1,33 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
// parameterized types with self-recursive constraints
|
||||
type (
|
||||
T1 /* ERROR illegal cycle */ [P T1[P]] interface{}
|
||||
T2 /* ERROR illegal cycle */ [P, Q T2[P, Q]] interface{}
|
||||
T3[P T2[P, Q], Q interface{ ~string }] interface{}
|
||||
|
||||
T4a /* ERROR illegal cycle */ [P T4a[P]] interface{ ~int }
|
||||
T4b /* ERROR illegal cycle */ [P T4b[int]] interface{ ~int }
|
||||
T4c /* ERROR illegal cycle */ [P T4c[string]] interface{ ~int }
|
||||
|
||||
// mutually recursive constraints
|
||||
T5 /* ERROR illegal cycle */ [P T6[P]] interface{ int }
|
||||
T6[P T5[P]] interface{ int }
|
||||
)
|
||||
|
||||
// verify that constraints are checked as expected
|
||||
var (
|
||||
_ T1[int]
|
||||
_ T2[int, string]
|
||||
_ T3[int, string]
|
||||
)
|
||||
|
||||
// test case from issue
|
||||
|
||||
type Eq /* ERROR illegal cycle */ [a Eq[a]] interface {
|
||||
Equal(that a) bool
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
// -lang=go1.17
|
||||
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Parser accepts type parameters but the type checker
|
||||
// needs to report any operations that are not permitted
|
||||
// before Go 1.18.
|
||||
|
||||
package p
|
||||
|
||||
type T[P /* ERROR type parameter requires go1\.18 or later */ any /* ERROR predeclared any requires go1\.18 or later */] struct{}
|
||||
|
||||
// for init (and main, but we're not in package main) we should only get one error
|
||||
func init[P /* ERROR func init must have no type parameters */ any /* ERROR predeclared any requires go1\.18 or later */]() {
|
||||
}
|
||||
func main[P /* ERROR type parameter requires go1\.18 or later */ any /* ERROR predeclared any requires go1\.18 or later */]() {
|
||||
}
|
||||
|
||||
func f[P /* ERROR type parameter requires go1\.18 or later */ any /* ERROR predeclared any requires go1\.18 or later */](x P) {
|
||||
var _ T[ /* ERROR type instantiation requires go1\.18 or later */ int]
|
||||
var _ (T[ /* ERROR type instantiation requires go1\.18 or later */ int])
|
||||
_ = T[ /* ERROR type instantiation requires go1\.18 or later */ int]{}
|
||||
_ = T[ /* ERROR type instantiation requires go1\.18 or later */ int](struct{}{})
|
||||
}
|
||||
|
||||
func (T[ /* ERROR type instantiation requires go1\.18 or later */ P]) g(x int) {
|
||||
f[ /* ERROR function instantiation requires go1\.18 or later */ int](0) // explicit instantiation
|
||||
(f[ /* ERROR function instantiation requires go1\.18 or later */ int])(0) // parentheses (different code path)
|
||||
f( /* ERROR implicit function instantiation requires go1\.18 or later */ x) // implicit instantiation
|
||||
}
|
||||
|
||||
type C1 interface {
|
||||
comparable // ERROR predeclared comparable requires go1\.18 or later
|
||||
}
|
||||
|
||||
type C2 interface {
|
||||
comparable // ERROR predeclared comparable requires go1\.18 or later
|
||||
int // ERROR embedding non-interface type int requires go1\.18 or later
|
||||
~ /* ERROR embedding interface element ~int requires go1\.18 or later */ int
|
||||
int /* ERROR embedding interface element int\|~string requires go1\.18 or later */ | ~string
|
||||
}
|
||||
|
||||
type _ interface {
|
||||
// errors for these were reported with their declaration
|
||||
C1
|
||||
C2
|
||||
}
|
||||
|
||||
type (
|
||||
_ comparable // ERROR predeclared comparable requires go1\.18 or later
|
||||
// errors for these were reported with their declaration
|
||||
_ C1
|
||||
_ C2
|
||||
|
||||
_ = comparable // ERROR predeclared comparable requires go1\.18 or later
|
||||
// errors for these were reported with their declaration
|
||||
_ = C1
|
||||
_ = C2
|
||||
)
|
@ -1,28 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type Fooer[t any] interface {
|
||||
foo(Barer[t])
|
||||
}
|
||||
type Barer[t any] interface {
|
||||
bar(Bazer[t])
|
||||
}
|
||||
type Bazer[t any] interface {
|
||||
Fooer[t]
|
||||
baz(t)
|
||||
}
|
||||
|
||||
type Int int
|
||||
|
||||
func (n Int) baz(int) {}
|
||||
func (n Int) foo(b Barer[int]) { b.bar(n) }
|
||||
|
||||
type F[t any] interface { f(G[t]) }
|
||||
type G[t any] interface { g(H[t]) }
|
||||
type H[t any] interface { F[t] }
|
||||
|
||||
type T struct{}
|
||||
func (n T) f(b G[T]) { b.g(n) }
|
@ -1,21 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type T[P any] struct{}
|
||||
|
||||
func (T[P]) m1()
|
||||
|
||||
type A1 = T // ERROR cannot use generic type
|
||||
|
||||
func (A1[P]) m2() {}
|
||||
|
||||
type A2 = T[int]
|
||||
|
||||
func (A2 /* ERROR cannot define new methods on instantiated type T\[int\] */) m3() {}
|
||||
func (_ /* ERROR cannot define new methods on instantiated type T\[int\] */ A2) m4() {}
|
||||
|
||||
func (T[int]) m5() {} // int is the type parameter name, not an instantiation
|
||||
func (T[* /* ERROR must be an identifier */ int]) m6() {} // syntax error
|
@ -1,60 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type T[P any] struct{}
|
||||
|
||||
func _(x interface{}) {
|
||||
switch x.(type) {
|
||||
case nil:
|
||||
case int:
|
||||
|
||||
case T[int]:
|
||||
case []T[int]:
|
||||
case [10]T[int]:
|
||||
case struct{T[int]}:
|
||||
case *T[int]:
|
||||
case func(T[int]):
|
||||
case interface{m(T[int])}:
|
||||
case map[T[int]] string:
|
||||
case chan T[int]:
|
||||
|
||||
case T /* ERROR cannot use generic type T\[P any\] without instantiation */ :
|
||||
case []T /* ERROR cannot use generic type */ :
|
||||
case [10]T /* ERROR cannot use generic type */ :
|
||||
case struct{T /* ERROR cannot use generic type */ }:
|
||||
case *T /* ERROR cannot use generic type */ :
|
||||
case func(T /* ERROR cannot use generic type */ ):
|
||||
case interface{m(T /* ERROR cannot use generic type */ )}:
|
||||
case map[T /* ERROR cannot use generic type */ ] string:
|
||||
case chan T /* ERROR cannot use generic type */ :
|
||||
|
||||
case T /* ERROR cannot use generic type */ , *T /* ERROR cannot use generic type */ :
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure a parenthesized nil is ok.
|
||||
|
||||
func _(x interface{}) {
|
||||
switch x.(type) {
|
||||
case ((nil)), int:
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we look for the predeclared nil.
|
||||
|
||||
func _(x interface{}) {
|
||||
type nil int
|
||||
switch x.(type) {
|
||||
case nil: // ok - this is the type nil
|
||||
}
|
||||
}
|
||||
|
||||
func _(x interface{}) {
|
||||
var nil int
|
||||
switch x.(type) {
|
||||
case nil /* ERROR not a type */ : // not ok - this is the variable nil
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
type Box[A any] struct {
|
||||
value A
|
||||
}
|
||||
|
||||
func Nest[A /* ERROR instantiation cycle */ any](b Box[A], n int) interface{} {
|
||||
if n == 0 {
|
||||
return b
|
||||
}
|
||||
return Nest(Box[Box[A]]{b}, n-1)
|
||||
}
|
||||
|
||||
func main() {
|
||||
Nest(Box[int]{0}, 10)
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type T[P any] struct{}
|
||||
|
||||
func (T[_]) A() {}
|
||||
|
||||
var _ = (T[int]).A
|
||||
var _ = (*T[int]).A
|
||||
|
||||
var _ = (T /* ERROR cannot use generic type */).A
|
||||
var _ = (*T /* ERROR cannot use generic type */).A
|
@ -1,7 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package issue48082
|
||||
|
||||
import "init" /* ERROR init must be a func */ /* ERROR could not import init */
|
@ -1,9 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type T[P any] struct{}
|
||||
|
||||
type _ interface{ int | T /* ERROR cannot use generic type */ }
|
@ -1,36 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func f1[P interface{ *P }]() {}
|
||||
func f2[P interface{ func(P) }]() {}
|
||||
func f3[P, Q interface{ func(Q) P }]() {}
|
||||
func f4[P interface{ *Q }, Q interface{ func(P) }]() {}
|
||||
func f5[P interface{ func(P) }]() {}
|
||||
func f6[P interface { *Tree[P] }, Q any ]() {}
|
||||
|
||||
func _() {
|
||||
f1 /* ERROR cannot infer P */ ()
|
||||
f2 /* ERROR cannot infer P */ ()
|
||||
f3 /* ERROR cannot infer P */ ()
|
||||
f4 /* ERROR cannot infer P */ ()
|
||||
f5 /* ERROR cannot infer P */ ()
|
||||
f6 /* ERROR cannot infer P */ ()
|
||||
}
|
||||
|
||||
type Tree[P any] struct {
|
||||
left, right *Tree[P]
|
||||
data P
|
||||
}
|
||||
|
||||
// test case from issue
|
||||
|
||||
func foo[Src interface { func() Src }]() Src {
|
||||
return foo[Src]
|
||||
}
|
||||
|
||||
func _() {
|
||||
foo /* ERROR cannot infer Src */ ()
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
var _ = interface{
|
||||
m()
|
||||
m /* ERROR "duplicate method" */ ()
|
||||
}(nil)
|
@ -1,20 +0,0 @@
|
||||
// Copyright 2022 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type T interface{ m() }
|
||||
type P *T
|
||||
|
||||
func _(p *T) {
|
||||
p.m /* ERROR type \*T is pointer to interface, not interface */ ()
|
||||
}
|
||||
|
||||
func _(p P) {
|
||||
p.m /* ERROR type P is pointer to interface, not interface */ ()
|
||||
}
|
||||
|
||||
func _[P T](p *P) {
|
||||
p.m /* ERROR type \*P is pointer to type parameter, not type parameter */ ()
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func g() {
|
||||
var s string
|
||||
var i int
|
||||
_ = s /* ERROR invalid operation: s \+ i \(mismatched types string and int\) */ + i
|
||||
}
|
||||
|
||||
func f(i int) int {
|
||||
i /* ERROR invalid operation: i \+= "1" \(mismatched types int and untyped string\) */ += "1"
|
||||
return i
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type T /* ERROR illegal cycle */ [U interface{ M() T[U, int] }] int
|
||||
|
||||
type X int
|
||||
|
||||
func (X) M() T[X] { return 0 }
|
@ -1,29 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type N /* ERROR cycle */ interface {
|
||||
int | N
|
||||
}
|
||||
|
||||
type A /* ERROR cycle */ interface {
|
||||
int | B
|
||||
}
|
||||
|
||||
type B interface {
|
||||
int | A
|
||||
}
|
||||
|
||||
type S /* ERROR cycle */ struct {
|
||||
I // ERROR interface contains type constraints
|
||||
}
|
||||
|
||||
type I interface {
|
||||
int | S
|
||||
}
|
||||
|
||||
type P interface {
|
||||
*P // ERROR interface contains type constraints
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func f[P any](a, _ P) {
|
||||
var x int
|
||||
// TODO(gri) these error messages, while correct, could be better
|
||||
f(a, x /* ERROR type int of x does not match inferred type P for P */)
|
||||
f(x, a /* ERROR type P of a does not match inferred type int for P */)
|
||||
}
|
||||
|
||||
func g[P any](a, b P) {
|
||||
g(a, b)
|
||||
g(&a, &b)
|
||||
g([]P{}, []P{})
|
||||
|
||||
// work-around: provide type argument explicitly
|
||||
g[*P](&a, &b)
|
||||
g[[]P]([]P{}, []P{})
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func f[P *Q, Q any](P, Q) {
|
||||
_ = f[P]
|
||||
}
|
||||
|
||||
func f2[P /* ERROR instantiation cycle */ *Q, Q any](P, Q) {
|
||||
_ = f2[*P]
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func g[P ~func(T) P, T any](P) {}
|
||||
|
||||
func _() {
|
||||
type F func(int) F
|
||||
var f F
|
||||
g(f)
|
||||
_ = g[F]
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
import "unsafe"
|
||||
|
||||
// The actual example from the issue.
|
||||
type List[P any] struct{}
|
||||
|
||||
func (_ List[P]) m() (_ List[List[P]]) { return }
|
||||
|
||||
// Other types of recursion through methods.
|
||||
type R[P any] int
|
||||
|
||||
func (*R[R /* ERROR must be an identifier */ [int]]) m0() {}
|
||||
func (R[P]) m1(R[R[P]]) {}
|
||||
func (R[P]) m2(R[*P]) {}
|
||||
func (R[P]) m3([unsafe.Sizeof(new(R[P]))]int) {}
|
||||
func (R[P]) m4([unsafe.Sizeof(new(R[R[P]]))]int) {}
|
||||
|
||||
// Mutual recursion
|
||||
type M[P any] int
|
||||
|
||||
func (R[P]) m5(M[M[P]]) {}
|
||||
func (M[P]) m(R[R[P]]) {}
|
@ -1,41 +0,0 @@
|
||||
// Copyright 2022 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func _[P comparable](x, y P) {
|
||||
_ = x == x
|
||||
_ = x == y
|
||||
_ = y == x
|
||||
_ = y == y
|
||||
|
||||
_ = x /* ERROR type parameter P is not comparable with < */ < y
|
||||
}
|
||||
|
||||
func _[P comparable](x P, y any) {
|
||||
_ = x == x
|
||||
_ = x == y
|
||||
_ = y == x
|
||||
_ = y == y
|
||||
|
||||
_ = x /* ERROR type parameter P is not comparable with < */ < y
|
||||
}
|
||||
|
||||
func _[P any](x, y P) {
|
||||
_ = x /* ERROR incomparable types in type set */ == x
|
||||
_ = x /* ERROR incomparable types in type set */ == y
|
||||
_ = y /* ERROR incomparable types in type set */ == x
|
||||
_ = y /* ERROR incomparable types in type set */ == y
|
||||
|
||||
_ = x /* ERROR type parameter P is not comparable with < */ < y
|
||||
}
|
||||
|
||||
func _[P any](x P, y any) {
|
||||
_ = x /* ERROR incomparable types in type set */ == x
|
||||
_ = x /* ERROR incomparable types in type set */ == y
|
||||
_ = y == x // ERROR incomparable types in type set
|
||||
_ = y == y
|
||||
|
||||
_ = x /* ERROR type parameter P is not comparable with < */ < y
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type T /* ERROR illegal cycle in declaration of T */ struct {
|
||||
T
|
||||
}
|
||||
|
||||
func _(t T) {
|
||||
_ = unsafe.Sizeof(t) // should not go into infinite recursion here
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type G[P any] int
|
||||
|
||||
type (
|
||||
_ G[int]
|
||||
_ G[G /* ERROR "cannot use.*without instantiation" */]
|
||||
_ bool /* ERROR "invalid operation: bool\[int\] \(bool is not a generic type\)" */ [int]
|
||||
_ bool /* ERROR "invalid operation: bool\[G\] \(bool is not a generic type\)" */[G]
|
||||
)
|
||||
|
||||
// The example from the issue.
|
||||
func _() {
|
||||
_ = &([10]bool /* ERROR "invalid operation.*bool is not a generic type" */ [1 /* ERROR "expected type" */ ]{})
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type (
|
||||
A1[P any] [10]A1 /* ERROR illegal cycle */ [P]
|
||||
A2[P any] [10]A2 /* ERROR illegal cycle */ [*P]
|
||||
A3[P any] [10]*A3[P]
|
||||
|
||||
L1[P any] []L1[P]
|
||||
|
||||
S1[P any] struct{ f S1 /* ERROR illegal cycle */ [P] }
|
||||
S2[P any] struct{ f S2 /* ERROR illegal cycle */ [*P] } // like example in issue
|
||||
S3[P any] struct{ f *S3[P] }
|
||||
|
||||
I1[P any] interface{ I1 /* ERROR illegal cycle */ [P] }
|
||||
I2[P any] interface{ I2 /* ERROR illegal cycle */ [*P] }
|
||||
I3[P any] interface{ *I3 /* ERROR interface contains type constraints */ [P] }
|
||||
)
|
@ -1,13 +0,0 @@
|
||||
// Copyright 2022 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type T0[P any] struct {
|
||||
f P
|
||||
}
|
||||
|
||||
type T1 /* ERROR illegal cycle */ struct {
|
||||
_ T0[T1]
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type Fooer interface {
|
||||
Foo()
|
||||
}
|
||||
|
||||
type Fooable[F /* ERROR instantiation cycle */ Fooer] struct {
|
||||
ptr F
|
||||
}
|
||||
|
||||
func (f *Fooable[F]) Adapter() *Fooable[*FooerImpl[F]] {
|
||||
return &Fooable[*FooerImpl[F]]{&FooerImpl[F]{}}
|
||||
}
|
||||
|
||||
type FooerImpl[F Fooer] struct {
|
||||
}
|
||||
|
||||
func (fi *FooerImpl[F]) Foo() {}
|
@ -1,10 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func f(s string) int {
|
||||
for range s {
|
||||
}
|
||||
} // ERROR missing return
|
@ -1,31 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type T1 interface{ M() }
|
||||
|
||||
func F1() T1
|
||||
|
||||
var _ = F1().(*X1 /* ERROR undeclared name: X1 */)
|
||||
|
||||
func _() {
|
||||
switch F1().(type) {
|
||||
case *X1 /* ERROR undeclared name: X1 */ :
|
||||
}
|
||||
}
|
||||
|
||||
type T2 interface{ M() }
|
||||
|
||||
func F2() T2
|
||||
|
||||
var _ = F2 /* ERROR impossible type assertion: F2\(\)\.\(\*X2\)\n\t\*X2 does not implement T2 \(missing method M\) */ ().(*X2)
|
||||
|
||||
type X2 struct{}
|
||||
|
||||
func _() {
|
||||
switch F2().(type) {
|
||||
case * /* ERROR impossible type switch case: \*X2\n\tF2\(\) \(value of type T2\) cannot have dynamic type \*X2 \(missing method M\) */ X2:
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
// The example from the issue.
|
||||
type (
|
||||
N[P any] M /* ERROR illegal cycle */ [P]
|
||||
M[P any] N /* ERROR illegal cycle */ [P]
|
||||
)
|
||||
|
||||
// A slightly more complicated case.
|
||||
type (
|
||||
A[P any] B /* ERROR illegal cycle */ [P]
|
||||
B[P any] C[P]
|
||||
C[P any] A[P]
|
||||
)
|
||||
|
||||
// Confusing but valid (note that `type T *T` is valid).
|
||||
type (
|
||||
N1[P any] *M1[P]
|
||||
M1[P any] *N1[P]
|
||||
)
|
@ -1,15 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func f[P int](P) {}
|
||||
|
||||
func _() {
|
||||
_ = f[int]
|
||||
_ = f[[ /* ERROR \[\]int does not implement int */ ]int]
|
||||
|
||||
f(0)
|
||||
f/* ERROR \[\]int does not implement int */ ([]int{})
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func f1[P int | string]() {}
|
||||
func f2[P ~int | string | float64]() {}
|
||||
func f3[P int](x P) {}
|
||||
|
||||
type myInt int
|
||||
type myFloat float64
|
||||
|
||||
func _() {
|
||||
_ = f1[int]
|
||||
_ = f1[myInt /* ERROR possibly missing ~ for int in constraint int\|string */]
|
||||
_ = f2[myInt]
|
||||
_ = f2[myFloat /* ERROR possibly missing ~ for float64 in constraint int\|string|float64 */]
|
||||
var x myInt
|
||||
f3 /* ERROR myInt does not implement int \(possibly missing ~ for int in constraint int\) */ (x)
|
||||
}
|
||||
|
||||
// test case from the issue
|
||||
|
||||
type SliceConstraint[T any] interface {
|
||||
[]T
|
||||
}
|
||||
|
||||
func Map[S SliceConstraint[E], E any](s S, f func(E) E) S {
|
||||
return s
|
||||
}
|
||||
|
||||
type MySlice []int
|
||||
|
||||
func f(s MySlice) {
|
||||
Map[MySlice /* ERROR MySlice does not implement SliceConstraint\[int\] \(possibly missing ~ for \[\]int in constraint SliceConstraint\[int\]\) */, int](s, nil)
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func _[P int](x P) int {
|
||||
return x // ERROR cannot use x .* as int value in return statement
|
||||
}
|
||||
|
||||
func _[P int]() int {
|
||||
return P /* ERROR cannot use P\(1\) .* as int value in return statement */ (1)
|
||||
}
|
||||
|
||||
func _[P int](x int) P {
|
||||
return x // ERROR cannot use x .* as P value in return statement
|
||||
}
|
||||
|
||||
func _[P, Q any](x P) Q {
|
||||
return x // ERROR cannot use x .* as Q value in return statement
|
||||
}
|
||||
|
||||
// test case from issue
|
||||
func F[G interface{ uint }]() int {
|
||||
f := func(uint) int { return 0 }
|
||||
return f(G /* ERROR cannot use G\(1\) .* as uint value in argument to f */ (1))
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type integer interface {
|
||||
~int | ~int8 | ~int16 | ~int32 | ~int64 |
|
||||
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
|
||||
}
|
||||
|
||||
func Add1024[T integer](s []T) {
|
||||
for i, v := range s {
|
||||
s[i] = v + 1024 // ERROR cannot convert 1024 \(untyped int constant\) to T
|
||||
}
|
||||
}
|
||||
|
||||
func f[T interface{ int8 }]() {
|
||||
println(T(1024 /* ERROR cannot convert 1024 \(untyped int value\) to T */))
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type S /* ERROR illegal cycle in declaration of S */ struct {
|
||||
_ [unsafe.Sizeof(s)]byte
|
||||
}
|
||||
|
||||
var s S
|
||||
|
||||
// Since f is a pointer, this case could be valid.
|
||||
// But it's pathological and not worth the expense.
|
||||
type T struct {
|
||||
f *[unsafe.Sizeof(T /* ERROR illegal cycle in type declaration */ {})]int
|
||||
}
|
||||
|
||||
// a mutually recursive case using unsafe.Sizeof
|
||||
type (
|
||||
A1 struct {
|
||||
_ [unsafe.Sizeof(B1{})]int
|
||||
}
|
||||
|
||||
B1 struct {
|
||||
_ [unsafe.Sizeof(A1 /* ERROR illegal cycle in type declaration */ {})]int
|
||||
}
|
||||
)
|
||||
|
||||
// a mutually recursive case using len
|
||||
type (
|
||||
A2 struct {
|
||||
f [len(B2{}.f)]int
|
||||
}
|
||||
|
||||
B2 struct {
|
||||
f [len(A2 /* ERROR illegal cycle in type declaration */ {}.f)]int
|
||||
}
|
||||
)
|
||||
|
||||
// test case from issue
|
||||
type a struct {
|
||||
_ [42 - unsafe.Sizeof(a /* ERROR illegal cycle in type declaration */ {})]byte
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func _[
|
||||
T0 any,
|
||||
T1 []int,
|
||||
T2 ~float64 | ~complex128 | chan int,
|
||||
]() {
|
||||
_ = T0(nil /* ERROR cannot convert nil to T0 */ )
|
||||
_ = T1(1 /* ERROR cannot convert 1 .* to T1 */ )
|
||||
_ = T2(2 /* ERROR cannot convert 2 .* to T2 */ )
|
||||
}
|
||||
|
||||
// test case from issue
|
||||
func f[T interface{[]int}]() {
|
||||
_ = T(1 /* ERROR cannot convert */ )
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type T0 /* ERROR illegal cycle */ [P T0[P]] struct{}
|
||||
|
||||
type T1 /* ERROR illegal cycle */ [P T2[P]] struct{}
|
||||
type T2[P T1[P]] struct{}
|
||||
|
||||
type T3 /* ERROR illegal cycle */ [P interface{ ~struct{ f T3[int] } }] struct{}
|
||||
|
||||
// valid cycle in M
|
||||
type N[P M[P]] struct{}
|
||||
type M[Q any] struct { F *M[Q] }
|
||||
|
||||
// "crazy" case
|
||||
type TC[P [unsafe.Sizeof(func() {
|
||||
type T [P [unsafe.Sizeof(func(){})]byte] struct{}
|
||||
})]byte] struct{}
|
||||
|
||||
// test case from issue
|
||||
type X /* ERROR illegal cycle */ [T any, PT X[T]] interface{}
|
@ -1,26 +0,0 @@
|
||||
// Copyright 2022 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
// The following is OK, per the special handling for type literals discussed in issue #49482.
|
||||
type _[P *struct{}] struct{}
|
||||
type _[P *int,] int
|
||||
type _[P (*int),] int
|
||||
|
||||
const P = 2 // declare P to avoid noisy 'undeclared name' errors below.
|
||||
|
||||
// The following parse as invalid array types due to parsing ambiguitiues.
|
||||
type _ [P *int /* ERROR "int \(type\) is not an expression" */ ]int
|
||||
type _ [P /* ERROR non-function P */ (*int)]int
|
||||
|
||||
// Adding a trailing comma or an enclosing interface resolves the ambiguity.
|
||||
type _[P *int,] int
|
||||
type _[P (*int),] int
|
||||
type _[P interface{*int}] int
|
||||
type _[P interface{(*int)}] int
|
||||
|
||||
// The following parse correctly as valid generic types.
|
||||
type _[P *struct{} | int] struct{}
|
||||
type _[P *struct{} | ~int] struct{}
|
@ -1,45 +0,0 @@
|
||||
// Copyright 2022 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type S[A, B any] struct {
|
||||
f int
|
||||
}
|
||||
|
||||
func (S[A, B]) m() {}
|
||||
|
||||
// TODO(gri): with type-type inference enabled we should only report one error
|
||||
// below. See issue #50588.
|
||||
|
||||
func _[A any](s S /* ERROR got 1 arguments but 2 type parameters */ [A]) {
|
||||
// we should see no follow-on errors below
|
||||
s.f = 1
|
||||
s.m()
|
||||
}
|
||||
|
||||
// another test case from the issue
|
||||
|
||||
func _() {
|
||||
X(Interface[*F /* ERROR got 1 arguments but 2 type parameters */ [string]](Impl{}))
|
||||
}
|
||||
|
||||
func X[Q Qer](fs Interface[Q]) {
|
||||
}
|
||||
|
||||
type Impl struct{}
|
||||
|
||||
func (Impl) M() {}
|
||||
|
||||
type Interface[Q Qer] interface {
|
||||
M()
|
||||
}
|
||||
|
||||
type Qer interface {
|
||||
Q()
|
||||
}
|
||||
|
||||
type F[A, B any] struct{}
|
||||
|
||||
func (f *F[A, B]) Q() {}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user