]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: consolidate testdata/fixedbugs test files
authorRobert Griesemer <gri@golang.org>
Wed, 31 Aug 2022 23:56:17 +0000 (16:56 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 2 Sep 2022 02:15:01 +0000 (02:15 +0000)
Use the go/types version of testdata/fixedbugs tests where diffs
are only in the error positions (the types2 test harness allows
for some position tolerance). Consolidate files where there are
other minor differences.

Add files to respective directories if they only existed for
one of the type checkers.

Move types2-only test issue47996.go out of testdata/fixedbugs
into testdata. Making it work for both type checkers requires
some more work.

With this CL, the testdata/fixedbugs files are identical between
the two type checkers.

For #54511.

Change-Id: I0d67f0db75ad1743c62da9181a6d0032c8bdb728
Reviewed-on: https://go-review.googlesource.com/c/go/+/427236
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
40 files changed:
src/cmd/compile/internal/types2/check_test.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue20583.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue26390.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue39634.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue39693.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue39711.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue40038.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue40056.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue40684.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue42987.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue43125.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue45635.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue45920.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue45985.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue46275.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue46403.go [new file with mode: 0644]
src/cmd/compile/internal/types2/testdata/fixedbugs/issue47115.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue47411.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue48136.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue48827.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue49112.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue49179.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue49602.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue50372.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue50427.go [new file with mode: 0644]
src/cmd/compile/internal/types2/testdata/fixedbugs/issue51229.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue51257.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue51339.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue51360.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue51376.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue51472.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue51593.go
src/cmd/compile/internal/types2/testdata/issue47996.go [moved from src/cmd/compile/internal/types2/testdata/fixedbugs/issue47996.go with 100% similarity]
src/go/types/testdata/fixedbugs/issue39693.go
src/go/types/testdata/fixedbugs/issue46275.go
src/go/types/testdata/fixedbugs/issue46583.go [new file with mode: 0644]
src/go/types/testdata/fixedbugs/issue48695.go
src/go/types/testdata/fixedbugs/issue49296.go
src/go/types/testdata/fixedbugs/issue50372.go [new file with mode: 0644]
src/go/types/testdata/fixedbugs/issue52698.go

index 3eab464b961a46f1d7aed85d16f6bab39cadea4f..d902b358c95109382d8e72f96e4982a589db65c4 100644 (file)
@@ -303,7 +303,7 @@ func TestCheck(t *testing.T) {
 }
 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)
index 85f11ecd38367d87340b47f070cb80fc9f29d3ad..d26dbada4fe71d3a03ad4d0ba147395d109b4934 100644 (file)
@@ -3,10 +3,12 @@
 // 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
 )
index b8e67e9bddb6a8b2794c792dfaa73a5ff861098a..9e0101f5819b9c4fbbee387d56408a7a8f51e073 100644 (file)
@@ -2,6 +2,8 @@
 // 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
index 5ae647c59616dedb0f71f5d701b6097026fa0777..9df72f990ee9c2714e35331556e812a8e4bc402a 100644 (file)
@@ -87,4 +87,4 @@ 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 */ ) }
\ No newline at end of file
+func x27() { e27 /* ERROR cannot infer T */ () }
index 301c13be41cce2b5fce7cec228cac0d9f1504f63..496754d972b0e1d203ded44daea088f515b35daf 100644 (file)
@@ -15,7 +15,7 @@ func Add1[T Number1](a, b T) T {
 }
 
 type Number2 interface {
-       int|float64
+       int | float64
 }
 
 func Add2[T Number2](a, b T) T {
index 8f3101235410c091910641c928113718e66d2bc4..d85fa03fc433bc77d34c4e16f4fbb923cfee8d32 100644 (file)
@@ -7,7 +7,7 @@ package p
 // 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 }
 }
index 0981a335da3aa91cc12538ddc976f1e34e428e6d..5f81fcbfaa7236bfcdd58114ac74847f9e709555 100644 (file)
@@ -12,4 +12,4 @@ func f[P interface{m(P)}]() {}
 
 func _() {
        _ = f[A[int]]
-}
\ No newline at end of file
+}
index a3f3eecca098c6dbbace1dbc19eee13069484b6c..66130c0a558ebaef7ec875d3072a818a65b16ff3 100644 (file)
@@ -5,7 +5,7 @@
 package p
 
 func _() {
-       NewS( /* ERROR cannot infer T */ ) .M()
+       NewS /* ERROR cannot infer T */ ().M()
 }
 
 type S struct {}
index 58d0f69f6503164328feb8990baa1d4bbf201c52..63a058d039d93448f745ec2ecc1d091dae93da13 100644 (file)
@@ -12,4 +12,4 @@ func g[_, _ any]() {}
 func _() {
        _ = f[T /* ERROR without instantiation */ ]
        _ = g[T /* ERROR without instantiation */ , T /* ERROR without instantiation */ ]
-}
\ No newline at end of file
+}
index 8aa3544272e7431b8238f55a04775d65ca1f127d..f58c63f8a3621b85f581bf1f4600b6ff4ede76e3 100644 (file)
@@ -5,4 +5,4 @@
 // 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
index c2bd970e251c246e015c945910af32fc458ced92..456888de6b419089e34f2a3ea740b0c97cd2ff15 100644 (file)
@@ -1,4 +1,4 @@
-// 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.
 
index 3d8e3453edc4821c8c2177f91584697911ecc11a..fc50797b17ca76929275a00ff343e0b25484bb72 100644 (file)
@@ -10,7 +10,7 @@ func main() {
 
 type N[T any] struct{}
 
-var _ N[] /* ERROR expected type */
+var _ N [] // ERROR expected type argument list
 
 type I interface {
        ~[]int
@@ -18,14 +18,14 @@ type I interface {
 
 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" */ ]
 }
index b113e104bc8e5ee5f84608aa287101965a6671ae..a0e2d0c970e50233835113ff55f6c43f9dd40485 100644 (file)
@@ -8,10 +8,10 @@ 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 _(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) }
index cea8c1498321c7182c490d262cd9b4f58a03190f..9a0f5e36970058c347a5f312609f6821c208be59 100644 (file)
@@ -9,5 +9,5 @@ func app[S interface{ ~[]T }, T any](s S, e T) S {
 }
 
 func _() {
-       _ = app[/* ERROR "S does not match" */int]
+       _ = app/* ERROR "S does not match" */[int]
 }
index f41ae26e4bdda6fd5815434d0c96887006154a9b..0862d5bb5a0ef6dac4311b39757ef8b952d8d5fe 100644 (file)
@@ -5,22 +5,22 @@
 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
 }
diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue46403.go b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue46403.go
new file mode 100644 (file)
index 0000000..9d47522
--- /dev/null
@@ -0,0 +1,11 @@
+// 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
+}
index 5c1fa80b29590c36afc799b26f724acf9767cf8f..a0bfe38de8b0509354163c1879db1e38da410bfa 100644 (file)
@@ -12,11 +12,11 @@ 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
+       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) {
@@ -24,11 +24,11 @@ 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) {
index 3f405baed7741808a958687f4e82559b7a5d39a7..db5fb32483c3b40617d1f946ae7b9f10fd5fdbe0 100644 (file)
@@ -15,12 +15,12 @@ func _[P comparable,
         _ = 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} */ ]
 }
index 0ab92df40fabc07b89d7e1ff0f6de1623392bb9e..b87f84ae642d68973a1eb1788e8c41f4731c636d 100644 (file)
@@ -12,12 +12,12 @@ 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 */ )
+        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 {
@@ -32,5 +32,5 @@ func foo[Src interface { func() Src }]() Src {
 }
 
 func _() {
-        foo( /* ERROR cannot infer Src */ )
+        foo /* ERROR cannot infer Src */ ()
 }
index 408031cdbc2bb210a4f2b28e357b2460d0ddfdc8..aa1d12aaf5c638ae107cd6105a486ce85d73c4b4 100644 (file)
@@ -15,5 +15,5 @@ type (
 
 // 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" */ ]{})
 }
index 0efc9066ec2061d34d2f5b4bdd33dd7a3bda62f5..61b757ccb2f631bbbb15cbe3bbff050904e2b156 100644 (file)
@@ -11,5 +11,5 @@ func _() {
         _ = 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{})
 }
index 75bea1807226079867458b918a6b88d69630f290..d4c8a897c65a4004a6dacbdc836846aca99b43ca 100644 (file)
@@ -17,7 +17,7 @@ func _() {
        _ = 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
index 9edbf14a5558643960bf48ca09f41fa70f71090a..208501fafd303e37e5c9920a57c42f52cf3aa9a8 100644 (file)
@@ -5,15 +5,15 @@
 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\)
 }
index 0f15dc0b620590376815b052069f3d907a080ac3..4c9b65a72f5563c2710ce7018c2ff5839e1dddf2 100644 (file)
@@ -11,8 +11,8 @@ func _(s []int) {
         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) {
@@ -22,6 +22,6 @@ 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 {}
 }
diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue50427.go b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue50427.go
new file mode 100644 (file)
index 0000000..d89d63e
--- /dev/null
@@ -0,0 +1,23 @@
+// 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" */
+
+}
index ef873e6ea89332a8a7047ae8fd6210bc5779397b..808b6471f6eb5f69ca314c0e3cc78fe8974830fe 100644 (file)
@@ -109,7 +109,7 @@ func _() {
        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]()
 
@@ -118,11 +118,11 @@ func _() {
        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]()
 }
 
index bc4208e6eead6c43a182b2923efe9ee3bc25f05c..8a3eb3278de9b462534e9b82876bc3951b353c0f 100644 (file)
@@ -39,7 +39,7 @@ func NewSetFromSlice[T comparable](items []T) *Set[T] {
 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},
        })
index 84e551d9ad6e698d6e1ce4f28d21a2f5a6147dd0..38f86109e364001f96cd693da4907a482db78ace 100644 (file)
@@ -12,7 +12,7 @@ type T[P any, B *P] struct{}
 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() {}
index 447ce036ae3126c34fcea4606cb9458b25fe0279..fe3de04dbfd346adb60957b151b32951a784687d 100644 (file)
@@ -5,9 +5,9 @@
 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 */
 }
index 4eba07180197f37f77f6a228c8320e7f2d25403f..d51607b7abb5fc2f67045e5618a42020bc250293 100644 (file)
@@ -12,7 +12,7 @@ func g[M map[K]V, K comparable, V any](M) {}
 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)
@@ -20,5 +20,5 @@ func _[M1 ~map[K]V, M2 map[K]V, K comparable, V any]() {
 
         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
 }
index f19d906d973265b06d20c3de83e4ce12c5ae0b49..3126770829081668277268c27a974f306af1e59f 100644 (file)
@@ -49,6 +49,6 @@ func f[T interface{comparable; []byte|string}](x T) {
 }
 
 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]
 }
index d323618ee876add80ad278e4a860a15eb9a79285..e06c39fac0829deffb10af25d490e2d26c3f2143 100644 (file)
@@ -9,5 +9,5 @@ func f[P interface{ m(R) }, R any]() {}
 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
 }
index ec7641902a12f3549eca15af28fda8a8ae808ebc..496754d972b0e1d203ded44daea088f515b35daf 100644 (file)
@@ -10,12 +10,12 @@ type Number1 interface {
        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 {
index 0ebde31c8e909c204eb586ea3ab4fdeb5cf15182..0862d5bb5a0ef6dac4311b39757ef8b952d8d5fe 100644 (file)
@@ -5,23 +5,22 @@
 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
 }
-
diff --git a/src/go/types/testdata/fixedbugs/issue46583.go b/src/go/types/testdata/fixedbugs/issue46583.go
new file mode 100644 (file)
index 0000000..da1f1ff
--- /dev/null
@@ -0,0 +1,28 @@
+// 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
+}
index 2d9e6a5f3ddab0d32b5a6163fd112ebb1f1ad6ee..9f4a76851d5dad0ec983630cbb97abf263011f88 100644 (file)
@@ -4,7 +4,7 @@
 
 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
index 0ad71ef4b2adb677f00ec677cb92a94536fdb1f3..eaa8e4dc7d8ad6d33c582f79c89d903da03b8721 100644 (file)
@@ -9,7 +9,6 @@ func _[
         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 */ )
diff --git a/src/go/types/testdata/fixedbugs/issue50372.go b/src/go/types/testdata/fixedbugs/issue50372.go
new file mode 100644 (file)
index 0000000..4c9b65a
--- /dev/null
@@ -0,0 +1,27 @@
+// 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 {}
+}
index 3babc21d926c36f297f576735c8e22c3a3671b51..d1b06a210da1cd3bb84a3c5f7589d9bc4d978ca1 100644 (file)
@@ -4,7 +4,7 @@
 
 package p
 
-// sanity check
+// correctness check: ensure that cycles through generic instantiations are detected
 type T[P any] struct {
        _ P
 }
@@ -13,18 +13,30 @@ type S /* ERROR illegal cycle */ struct {
        _ 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
 }