From 914195c132cbec651aa43c409e8aac2614b53b38 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 10 Mar 2022 12:43:10 -0800 Subject: [PATCH] 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 --- src/cmd/compile/internal/types2/infer.go | 2 -- .../types2/testdata/fixedbugs/issue51593.go2 | 13 +++++++++++++ src/go/types/infer.go | 2 -- src/go/types/testdata/fixedbugs/issue51593.go2 | 13 +++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 src/cmd/compile/internal/types2/testdata/fixedbugs/issue51593.go2 create mode 100644 src/go/types/testdata/fixedbugs/issue51593.go2 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 +} -- 2.48.1