Skip to content

Commit 0fcbfdb

Browse files
authored
Merge pull request scala#5321 from dotty-staging/fix-#5269
Fix scala#5269: Fix StagedTuple/Tuple implementation
2 parents c02501a + 872a20e commit 0fcbfdb

File tree

5 files changed

+11
-3
lines changed

5 files changed

+11
-3
lines changed

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ class CompilationTests extends ParallelTesting {
171171
@Test def runAll: Unit = {
172172
implicit val testGroup: TestGroup = TestGroup("runAll")
173173
compileFilesInDir("tests/run-custom-args/Yretain-trees", defaultOptions and "-Yretain-trees") +
174+
compileFile("tests/run-custom-args/tuple-cons.scala", allowDeepSubtypes) +
174175
compileFilesInDir("tests/run", defaultOptions)
175176
}.checkRuns()
176177

library/src-scala3/scala/StagedTuple.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ object StagedTuple {
3030

3131
def fromArrayStaged[T <: Tuple : Type](xs: Expr[Array[Object]], size: Option[Int]): Expr[T] = {
3232
if (!specialize) '(dynamicFromArray[T](~xs))
33-
else {
33+
else xs.bind { xs =>
3434
val tup: Expr[Any] = size match {
3535
case Some(0) => '()
3636
case Some(1) => '(Tuple1( (~xs)(0)))
@@ -190,7 +190,7 @@ object StagedTuple {
190190
case Some(4) =>
191191
self.as[Tuple4[_, _, _, _]].bind(t => '(Tuple5(~x, (~t)._1, (~t)._2, (~t)._3, (~t)._4)))
192192
case Some(n) =>
193-
fromArrayStaged('($consArray(~x, ~toArrayStaged(self, tailSize))), Some(n + 1))
193+
fromArrayStaged[H *: T]('($consArray(~x, ~toArrayStaged(self, tailSize))), Some(n + 1))
194194
case _ =>
195195
'(dynamic_*:[T, H](~self, ~x))
196196
}

library/src-scala3/scala/Tuple.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ object Tuple {
131131
val t = self.asInstanceOf[Tuple4[Object, Object, Object, Object]]
132132
Array(t._1, t._2, t._3, t._4)
133133
case self: TupleXXL =>
134-
asInstanceOf[TupleXXL].elems
134+
self.elems
135135
case self: Product =>
136136
val arr = new Array[Object](self.productArity)
137137
for (i <- 0 until arr.length) arr(i) = self.productElement(i).asInstanceOf[Object]

tests/run/tuple-cons-2.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
object Test {
3+
def main(args: Array[String]): Unit = {
4+
val t6: (Int,Int,Int,Int,Int,Int) = 1 *: (2, 3, 4, 5, 6)
5+
println(t6)
6+
}
7+
}

0 commit comments

Comments
 (0)