Skip to content

Commit

Permalink
Merge pull request #41 from dotty-staging/generic-tuples
Browse files Browse the repository at this point in the history
Generic tuples improvements
  • Loading branch information
odersky authored May 6, 2024
2 parents 93281d1 + 9b7fa6a commit 9c3cf4e
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 178 deletions.
1 change: 0 additions & 1 deletion compiler/test/dotc/pos-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ mt-redux-norm.perspective.scala
i18211.scala
10867.scala
named-tuples1.scala
named-tuples-strawman-2.scala

# Opaque type
i5720.scala
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotc/run-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ t6138-2
i12656.scala
trait-static-forwarder
i17255
named-tuples-strawman-2.scala

323 changes: 155 additions & 168 deletions library/src/scala/Tuple.scala

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions library/src/scala/runtime/Tuples.scala
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ object Tuples {
}
}

def tail(self: NonEmptyTuple): Tuple = (self: Any) match {
def tail(self: Tuple): Tuple = (self: Any) match {
case xxl: TupleXXL => xxlTail(xxl)
case _ => specialCaseTail(self)
}
Expand Down Expand Up @@ -565,16 +565,16 @@ object Tuples {
}
}

def init(self: NonEmptyTuple): Tuple = (self: Any) match {
def init(self: Tuple): Tuple = (self: Any) match {
case xxl: TupleXXL => xxlInit(xxl)
case _ => specialCaseInit(self)
}

def last(self: NonEmptyTuple): Any = (self: Any) match {
def last(self: Tuple): Any = (self: Any) match {
case self: Product => self.productElement(self.productArity - 1)
}

def apply(self: NonEmptyTuple, n: Int): Any =
def apply(self: Tuple, n: Int): Any =
self.productElement(n)

// Benchmarks showed that this is faster than doing (it1 zip it2).copyToArray(...)
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/print-tuple-union.check
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
| and cannot be shown to be disjoint from it either.
| Therefore, reduction cannot advance to the remaining case
|
| case h *: t => h | Tuple.Fold[t, Nothing, [x, y] =>> x | y]
| case x *: xs => x | Tuple.Fold[xs, Nothing, [x, y] =>> x | y]
|
| longer explanation available when compiling with `-explain`
7 changes: 3 additions & 4 deletions tests/neg/wildcard-match.check
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@
| trying to reduce shapeless.tuples.length[T2]
| trying to reduce Tuple.Size[shapeless.tuples.to[T2]]
| failed since selector shapeless.tuples.to[T2]
| does not uniquely determine parameters x, xs in
| case x *: xs => scala.compiletime.ops.int.S[Tuple.Size[xs]]
| The computed bounds for the parameters are:
| x <: Int
| does not uniquely determine parameter xs in
| case _ *: xs => scala.compiletime.ops.int.S[Tuple.Size[xs]]
| The computed bounds for the parameter are:
| xs <: (Int, Int)
2 changes: 2 additions & 0 deletions tests/pos/fieldsOf.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import language.experimental.namedTuples

case class Person(name: String, age: Int)

type PF = NamedTuple.From[Person]
Expand Down
3 changes: 3 additions & 0 deletions tests/pos/tuple-filter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ def Test =
summon[Tuple.Filter[(1, 2, 3, 4), P] =:= (1, 2, 4)]
summon[Tuple.Filter[(1, 2, 3, 4), RejectAll] =:= EmptyTuple]
summon[Tuple.Filter[EmptyTuple, P] =:= EmptyTuple]

import compiletime.ops.int.<
summon[Tuple.Filter[(1, 4, 7, 2, 10, 3, 4), [X <: Int] =>> X < 5] =:= (1, 4, 2, 3, 4)]
File renamed without changes.

0 comments on commit 9c3cf4e

Please sign in to comment.