-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: implement alternative comparable semantics
This is an experiment to see the impact of a potential spec change: As an exception to the rule that constraint satisfaction is the same as interface implementation, if the flag Config.AltComparableSemantics is set, an ordinary (non-type parameter) interface satisfies the comparable constraint. (In go/types, the flag is not exported to avoid changing the API.) Disabled by default. Test files can set the flag by adding // -altComparableSemantics as the first line in the file. For #52509. Change-Id: Ib491b086feb5563920eaddefcebdacb2c5b72d61 Reviewed-on: https://go-review.googlesource.com/c/go/+/444635 Reviewed-by: Robert Findley <rfindley@google.com> Run-TryBot: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
- Loading branch information
Showing
11 changed files
with
70 additions
and
16 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
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
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
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
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
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,28 @@ | ||
// -altComparableSemantics | ||
|
||
// 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 f1[_ comparable]() {} | ||
func f2[_ interface{ comparable }]() {} | ||
|
||
type T interface{ m() } | ||
|
||
func _[P comparable, Q ~int, R any]() { | ||
_ = f1[int] | ||
_ = f1[T /* T does implement comparable */] | ||
_ = f1[any /* any does implement comparable */] | ||
_ = f1[P] | ||
_ = f1[Q] | ||
_ = f1[R /* ERROR R does not implement comparable */] | ||
|
||
_ = f2[int] | ||
_ = f2[T /* T does implement comparable */] | ||
_ = f2[any /* any does implement comparable */] | ||
_ = f2[P] | ||
_ = f2[Q] | ||
_ = f2[R /* ERROR R does not implement comparable */] | ||
} |