]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: remove incorrect assertion (don't crash)
authorRobert Griesemer <gri@golang.org>
Thu, 10 Mar 2022 20:43:10 +0000 (12:43 -0800)
committerRobert Griesemer <gri@golang.org>
Thu, 10 Mar 2022 21:10:30 +0000 (21:10 +0000)
The removed assertion was never incorrect, as signatures may
be from methods in interfaces, and (some) interfaces set the
receivers of their methods (so we have a position for error
reporting).

This CL changes the issue below from a release blocker to an
issue for Go 1.19.

For #51593.

Change-Id: I0c5f2913b397b9ab557ed74a80cc7a715e840412
Reviewed-on: https://go-review.googlesource.com/c/go/+/391615
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/compile/internal/types2/infer.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue51593.go2 [new file with mode: 0644]
src/go/types/infer.go
src/go/types/testdata/fixedbugs/issue51593.go2 [new file with mode: 0644]

index 29633028f35f902f0703feb409e41aaba2501cfe..e131077371601ed1468b9270377031e4438452c2 100644 (file)
@@ -739,8 +739,6 @@ func (w *cycleFinder) typ(typ Type) {
        //      in signatures where they are handled explicitly.
 
        case *Signature:
-               // There are no "method types" so we should never see a recv.
-               assert(t.recv == nil)
                if t.params != nil {
                        w.varList(t.params.vars)
                }
diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51593.go2 b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51593.go2
new file mode 100644 (file)
index 0000000..d323618
--- /dev/null
@@ -0,0 +1,13 @@
+// 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 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
+}
index 429510291ed728e2eceeaf00ada203464b350c34..6bed55c270f46b15359001437004266db2ec074c 100644 (file)
@@ -738,8 +738,6 @@ func (w *cycleFinder) typ(typ Type) {
        //      in signatures where they are handled explicitly.
 
        case *Signature:
-               // There are no "method types" so we should never see a recv.
-               assert(t.recv == nil)
                if t.params != nil {
                        w.varList(t.params.vars)
                }
diff --git a/src/go/types/testdata/fixedbugs/issue51593.go2 b/src/go/types/testdata/fixedbugs/issue51593.go2
new file mode 100644 (file)
index 0000000..e06c39f
--- /dev/null
@@ -0,0 +1,13 @@
+// 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 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
+}