-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle TypeProxy of Named Tuples in unapply (#22325)
Fixes #22150. Previously, there were several ways to check if something was a Named Tuple (`derivesFromNamedTuple`, `isNamedTupleType` and `NamedTuple.unapply`), this PR moves everything into `NamedTuple.unapply`. `namedTupleElementTypes` now takes an argument `derived` that when false will skip `unapply` (to avoid infinite recursion, used in desugaring and RefinedPrinter where trees can have invalid cycles).
- Loading branch information
Showing
10 changed files
with
71 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
0 | ||
1 | ||
2 |
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,26 @@ | ||
//> using options -experimental -language:experimental.namedTuples | ||
import language.experimental.namedTuples | ||
|
||
val directionsNT = IArray( | ||
(dx = 0, dy = 1), // up | ||
(dx = 1, dy = 0), // right | ||
(dx = 0, dy = -1), // down | ||
(dx = -1, dy = 0), // left | ||
) | ||
val IArray(UpNT @ _, _, _, _) = directionsNT | ||
|
||
object NT: | ||
def foo[T <: (x: Int, y: String)](tup: T): Int = | ||
tup.x | ||
|
||
def union[T](tup: (x: Int, y: String) | (x: Int, y: String)): Int = | ||
tup.x | ||
|
||
def intersect[T](tup: (x: Int, y: String) & T): Int = | ||
tup.x | ||
|
||
|
||
@main def Test = | ||
println(UpNT.dx) | ||
println(NT.union((1, "a"))) | ||
println(NT.intersect((2, "b"))) |