From: Robert Griesemer Date: Thu, 10 Mar 2022 20:43:10 +0000 (-0800) Subject: [release-branch.go1.18] go/types, types2: remove incorrect assertion (don't crash) X-Git-Tag: go1.18~5 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=8706c096227ce8a7f47798699232eac453a335dd;p=gostls13.git [release-branch.go1.18] 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 Run-TryBot: Robert Griesemer Reviewed-by: Robert Findley TryBot-Result: Gopher Robot (cherry picked from commit 914195c132cbec651aa43c409e8aac2614b53b38) Reviewed-on: https://go-review.googlesource.com/c/go/+/391796 Trust: Dmitri Shuralyov Run-TryBot: Dmitri Shuralyov Reviewed-by: Robert Griesemer --- diff --git a/src/cmd/compile/internal/types2/infer.go b/src/cmd/compile/internal/types2/infer.go index 29633028f3..e131077371 100644 --- a/src/cmd/compile/internal/types2/infer.go +++ b/src/cmd/compile/internal/types2/infer.go @@ -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 index 0000000000..d323618ee8 --- /dev/null +++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51593.go2 @@ -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 +} diff --git a/src/go/types/infer.go b/src/go/types/infer.go index 429510291e..6bed55c270 100644 --- a/src/go/types/infer.go +++ b/src/go/types/infer.go @@ -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 index 0000000000..e06c39fac0 --- /dev/null +++ b/src/go/types/testdata/fixedbugs/issue51593.go2 @@ -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 +}