Skip to content

Commit 914195c

Browse files
committed
go/types, types2: remove incorrect assertion (don't crash)
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 <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> Reviewed-by: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 2e46a0a commit 914195c

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

src/cmd/compile/internal/types2/infer.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,8 +739,6 @@ func (w *cycleFinder) typ(typ Type) {
739739
// in signatures where they are handled explicitly.
740740

741741
case *Signature:
742-
// There are no "method types" so we should never see a recv.
743-
assert(t.recv == nil)
744742
if t.params != nil {
745743
w.varList(t.params.vars)
746744
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package p
6+
7+
func f[P interface{ m(R) }, R any]() {}
8+
9+
type T = interface { m(int) }
10+
11+
func _() {
12+
_ = f[ /* ERROR cannot infer R */ T] // don't crash in type inference
13+
}

src/go/types/infer.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,6 @@ func (w *cycleFinder) typ(typ Type) {
738738
// in signatures where they are handled explicitly.
739739

740740
case *Signature:
741-
// There are no "method types" so we should never see a recv.
742-
assert(t.recv == nil)
743741
if t.params != nil {
744742
w.varList(t.params.vars)
745743
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package p
6+
7+
func f[P interface{ m(R) }, R any]() {}
8+
9+
type T = interface { m(int) }
10+
11+
func _() {
12+
_ = f /* ERROR cannot infer R */ [T] // don't crash in type inference
13+
}

0 commit comments

Comments
 (0)