}
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", 0, false) }
+func TestFixedbugs(t *testing.T) { testDirFiles(t, "testdata/fixedbugs", 100, false) } // TODO(gri) narrow column tolerance
func testDirFiles(t *testing.T, dir string, colDelta uint, manual bool) {
testenv.MustHaveGoBuild(t)
// 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
)
// 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
// crash 27
func e27[T any]() interface{ x27 /* ERROR not a type */ } { panic(0) }
-func x27() { e27( /* ERROR cannot infer T */ ) }
\ No newline at end of file
+func x27() { e27 /* ERROR cannot infer T */ () }
}
type Number2 interface {
- int|float64
+ int | float64
}
func Add2[T Number2](a, b T) T {
// Do not report a duplicate type error for this term list.
// (Check types after interfaces have been completed.)
type _ interface {
- // TODO(gri) Once we have full type sets we can enable this again.
+ // 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 }
}
func _() {
_ = f[A[int]]
-}
\ No newline at end of file
+}
package p
func _() {
- NewS( /* ERROR cannot infer T */ ) .M()
+ NewS /* ERROR cannot infer T */ ().M()
}
type S struct {}
func _() {
_ = f[T /* ERROR without instantiation */ ]
_ = g[T /* ERROR without instantiation */ , T /* ERROR without instantiation */ ]
-}
\ No newline at end of file
+}
// Check that there is only one error (no follow-on errors).
package p
-var _ = [ /* ERROR invalid use of .* array */ ...]byte("foo")
+var _ = [ ... /* ERROR invalid use of \[...\] array */ ]byte("foo")
\ No newline at end of file
-// Copyright 2020 The Go Authors. All rights reserved.
+// 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.
type N[T any] struct{}
-var _ N[] /* ERROR expected type */
+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 */ ]
+ _ = m[i, j /* ERROR "more than one index" */ ]
var a [3]int
- _ = a[i, j /* ERROR more than one index */ ]
+ _ = a[i, j /* ERROR "more than one index" */ ]
var s []int
- _ = s[i, j /* ERROR more than one index */ ]
+ _ = s[i, j /* ERROR "more than one index" */ ]
var t T
- _ = t[i, j /* ERROR more than one index */ ]
+ _ = t[i, j /* ERROR "more than one index" */ ]
}
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 _(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 /* ERROR <-chan int does not implement chan int\|chan<- int */ (ch) }
func _(ch chan<- int) { f2(ch) }
}
func _() {
- _ = app[/* ERROR "S does not match" */int]
+ _ = app/* ERROR "S does not match" */[int]
}
package issue46275
type N[T any] struct {
- *N[T]
- t T
+ *N[T]
+ t T
}
func (n *N[T]) Elem() T {
- return n.t
+ return n.t
}
type I interface {
- Elem() string
+ Elem() string
}
func _() {
- var n1 *N[string]
- var _ I = n1
- type NS N[string]
- var n2 *NS
- var _ I = n2
+ var n1 *N[string]
+ var _ I = n1
+ type NS N[string]
+ var n2 *NS
+ var _ I = n2
}
--- /dev/null
+// 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
+}
type C5[T any] interface{ ~chan T | chan<- T }
func _[T any](ch T) {
- ch /* ERROR cannot send to ch .* no core type */ <- 0
+ ch <- /* ERROR cannot send to ch .* no core type */ 0
}
func _[T C0](ch T) {
- ch /* ERROR cannot send to non-channel */ <- 0
+ ch <- /* ERROR cannot send to non-channel */ 0
}
func _[T C1](ch T) {
}
func _[T C2](ch T) {
- ch /* ERROR cannot send to receive-only channel */ <- 0
+ ch <-/* ERROR cannot send to receive-only channel */ 0
}
func _[T C3](ch T) {
- ch /* ERROR cannot send to ch .* no core type */ <- 0
+ ch <- /* ERROR cannot send to ch .* no core type */ 0
}
func _[T C4](ch T) {
_ = f[int]
_ = f[P]
_ = f[Q]
- _ = f[func( /* ERROR does not implement comparable */ )]
+ _ = 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[func /* ERROR func\(\) does not implement interface{interface{comparable; ~int\|~string}} */ ()]
_ = g[R /* ERROR R does not implement interface{interface{comparable; ~int\|~string} */ ]
}
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 */ )
+ 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 {
}
func _() {
- foo( /* ERROR cannot infer Src */ )
+ foo /* ERROR cannot infer Src */ ()
}
// The example from the issue.
func _() {
- _ = &([10]bool /* ERROR "invalid operation.*bool is not a generic type" */ [1 /* ERROR expected type */ ]{})
+ _ = &([10]bool /* ERROR "invalid operation.*bool is not a generic type" */ [1 /* ERROR "expected type" */ ]{})
}
_ = f[[ /* ERROR \[\]int does not implement int */ ]int]
f(0)
- f( /* ERROR \[\]int does not implement int */ []int{})
+ f/* ERROR \[\]int does not implement int */ ([]int{})
}
_ = 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)
+ f3 /* ERROR myInt does not implement int \(possibly missing ~ for int in constraint int\) */ (x)
}
// test case from the issue
package p
type M interface {
- m()
+ m()
}
type C interface {
- comparable
+ comparable
}
-type _ interface{
- int | M // ERROR cannot use p\.M in union \(p\.M contains methods\)
- int | comparable // ERROR cannot use comparable in union
- int | C // ERROR cannot use p\.C in union \(p\.C embeds comparable\)
+type _ interface {
+ int | M // ERROR cannot use p\.M in union \(p\.M contains methods\)
+ int | comparable // ERROR cannot use comparable in union
+ int | C // ERROR cannot use p\.C in union \(p\.C embeds comparable\)
}
for range s {}
for i = range s {}
for i, j = range s {}
- for i, j, k /* ERROR range clause permits at most two iteration variables */ = range s {}
- for i, j, k /* ERROR range clause permits at most two iteration variables */, l = range s {}
+ for i, j, k /* ERROR range clause permits at most two iteration variables|at most 2 expressions */ = range s {}
+ for i, j, k, l /* ERROR range clause permits at most two iteration variables|at most 2 expressions */ = range s {}
}
func _(s chan int) {
for range s {}
for i = range s {}
for i, j /* ERROR range over .* permits only one iteration variable */ = range s {}
- for i, j /* ERROR range over .* permits only one iteration variable */, k = range s {}
- for i, j /* ERROR range over .* permits only one iteration variable */, k, l = range s {}
+ for i, j, k /* ERROR range over .* permits only one iteration variable|at most 2 expressions */ = range s {}
+ for i, j, k, l /* ERROR range over .* permits only one iteration variable|at most 2 expressions */ = range s {}
}
--- /dev/null
+// 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 parser no longer parses type parameters for methods.
+// In the past, type checking the code below led to a crash (#50427).
+
+type T interface{ m[ /* ERROR "must have no type parameters" */ P any]() }
+
+func _(t T) {
+ var _ interface{ m[ /* ERROR "must have no type parameters" */ P any](); n() } = t /* ERROR "does not implement" */
+}
+
+type S struct{}
+
+func (S) m[ /* ERROR "must have no type parameters" */ P any]() {}
+
+func _(s S) {
+ var _ interface{ m[ /* ERROR "must have no type parameters" */ P any](); n() } = s /* ERROR "does not implement" */
+
+}
var _ chan<- int = ch1()
// P cannot be inferred as there's a tilde.
- ch2( /* ERROR cannot infer P */ )
+ ch2 /* ERROR cannot infer P */ ()
type myChan chan int
ch2[myChan]()
ch3(e)
// P cannot be inferred as there's more than one specific type and a tilde.
- ch4( /* ERROR cannot infer P */ e)
+ ch4 /* ERROR cannot infer P */ (e)
_ = ch4[chan int]
// P cannot be inferred as there's more than one specific type.
- ch5( /* ERROR cannot infer P */ )
+ ch5 /* ERROR cannot infer P */ ()
ch5[chan<- int]()
}
type T struct{ x any }
func main() {
- NewSetFromSlice( /* ERROR T does not implement comparable */ []T{
+ NewSetFromSlice /* ERROR T does not implement comparable */ ([]T{
{"foo"},
{5},
})
func (T /* ERROR cannot use generic type */ ) m0() {}
// TODO(rfindley): eliminate the duplicate errors here.
-func (T /* ERROR got 1 type parameter, but receiver base type declares 2 */ /* ERROR got 1 arguments but 2 type parameters */ [_]) m1() {}
+func (/* ERROR got 1 type parameter, but receiver base type declares 2 */ T /* ERROR got 1 arguments but 2 type parameters */ [_]) m1() {}
func (T[_, _]) m2() {}
// TODO(gri) this error is unfortunate (issue #51343)
func (T /* ERROR got 3 arguments but 2 type parameters */ [_, _, _]) m3() {}
package p
func _() {
- len. /* ERROR cannot select on len */ Println
- len. /* ERROR cannot select on len */ Println()
- _ = len. /* ERROR cannot select on len */ Println
- _ = len[ /* ERROR cannot index len */ 0]
+ len.Println /* ERROR cannot select on len */
+ len.Println /* ERROR cannot select on len */ ()
+ _ = len.Println /* ERROR cannot select on len */
+ _ = len /* ERROR cannot index len */ [0]
_ = *len /* ERROR cannot indirect len */
}
func _[M1 ~map[K]V, M2 map[K]V, K comparable, V any]() {
var m1 M1
f(m1)
- g( /* ERROR M1 does not implement map\[K\]V */ m1) // M1 has tilde
+ g /* ERROR M1 does not implement map\[K\]V */ (m1) // M1 has tilde
var m2 M2
f(m2)
var m3 Map
f(m3)
- g( /* ERROR Map does not implement map\[string\]int */ m3) // M in g does not have tilde
+ g /* ERROR Map does not implement map\[string\]int */ (m3) // M in g does not have tilde
}
}
func _(s []byte) {
- f( /* ERROR \[\]byte does not implement interface{comparable; \[\]byte\|string} */ s)
+ f /* ERROR \[\]byte does not implement interface{comparable; \[\]byte\|string} */ (s)
_ = f[[ /* ERROR does not implement */ ]byte]
}
type T = interface { m(int) }
func _() {
- _ = f[ /* ERROR cannot infer R */ T] // don't crash in type inference
+ _ = f /* ERROR cannot infer R */ [T] // don't crash in type inference
}
float64
}
-func Add[T Number1](a, b T) T {
+func Add1[T Number1](a, b T) T {
return a /* ERROR not defined */ + b
}
type Number2 interface {
- int|float64
+ int | float64
}
func Add2[T Number2](a, b T) T {
package issue46275
type N[T any] struct {
- *N[T]
- t T
+ *N[T]
+ t T
}
func (n *N[T]) Elem() T {
- return n.t
+ return n.t
}
type I interface {
- Elem() string
+ Elem() string
}
func _() {
- var n1 *N[string]
- var _ I = n1
- type NS N[string]
- var n2 *NS
- var _ I = n2
+ var n1 *N[string]
+ var _ I = n1
+ type NS N[string]
+ var n2 *NS
+ var _ I = n2
}
-
--- /dev/null
+// 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
+}
package p
-func g[P interface{~func(T) P}, T any](P) {}
+func g[P ~func(T) P, T any](P) {}
func _() {
type F func(int) F
T1 []int,
T2 ~float64 | ~complex128 | chan int,
]() {
- // TODO(rfindley): the types2 error here is clearer.
_ = T0(nil /* ERROR cannot convert nil to T0 */ )
_ = T1(1 /* ERROR cannot convert 1 .* to T1 */ )
_ = T2(2 /* ERROR cannot convert 2 .* to T2 */ )
--- /dev/null
+// 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 _(s []int) {
+ var i, j, k, l int
+ _, _, _, _ = i, j, k, l
+
+ for range s {}
+ for i = range s {}
+ for i, j = range s {}
+ for i, j, k /* ERROR range clause permits at most two iteration variables|at most 2 expressions */ = range s {}
+ for i, j, k, l /* ERROR range clause permits at most two iteration variables|at most 2 expressions */ = range s {}
+}
+
+func _(s chan int) {
+ var i, j, k, l int
+ _, _, _, _ = i, j, k, l
+
+ for range s {}
+ for i = range s {}
+ for i, j /* ERROR range over .* permits only one iteration variable */ = range s {}
+ for i, j, k /* ERROR range over .* permits only one iteration variable|at most 2 expressions */ = range s {}
+ for i, j, k, l /* ERROR range over .* permits only one iteration variable|at most 2 expressions */ = range s {}
+}
package p
-// sanity check
+// correctness check: ensure that cycles through generic instantiations are detected
type T[P any] struct {
_ P
}
_ T[S]
}
-// simplified test
-var _ B[A]
+// simplified test 1
-type A struct {
- _ B[string]
+var _ A1[A1[string]]
+
+type A1[P any] struct {
+ _ B1[P]
+}
+
+type B1[P any] struct {
+ _ P
+}
+
+// simplified test 2
+var _ B2[A2]
+
+type A2 struct {
+ _ B2[string]
}
-type B[P any] struct {
- _ C[P]
+type B2[P any] struct {
+ _ C2[P]
}
-type C[P any] struct {
+type C2[P any] struct {
_ P
}