-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/types, types2: eagerly check that constraints are not type params
As a result of the change to the underlying of a type parameter to be its constraint interface, we had couple inaccuracies that combined to cause an infinite recursion when type checking the invalid type parameter list [A A]. - We deferred tpar.iface() using check.later twice: once in newTypeParam, and then again at the end of collectTypeParams. - We deferred the check that type parameter constraints are not type parameters, even though this is unnecessary: the constraint type is known. With these inaccuracies, tpar.iface() was executing before our guard against using type parameters as constraints, causing an infinite recursion through under(). Fix this by eagerly checking whether the constraint is a type parameter, and marking it invalid if so. Also remove the unnecessary calls to tpar.iface() at the end of collectTypeParams, as this will already have been scheduled by newTypeParam. Fixes golang#50321 Change-Id: I4eecbecf21656615867cb94be65b520e9e795bd1 Reviewed-on: https://go-review.googlesource.com/c/go/+/374294 Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
- Loading branch information
Showing
4 changed files
with
34 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/cmd/compile/internal/types2/testdata/fixedbugs/issue50321.go2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// 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 Ln[A A /* ERROR cannot use a type parameter as constraint */ ](p A) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// 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 Ln[A A /* ERROR cannot use a type parameter as constraint */ ](p A) { | ||
} |