Skip to content

Commit c415033

Browse files
authored
Merge pull request #12356 from dotty-staging/fix-12093
Fix #12093: Simplify types after parameter instantiation
2 parents 02441d6 + c64bef0 commit c415033

File tree

8 files changed

+51
-12
lines changed

8 files changed

+51
-12
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -2852,7 +2852,7 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
28522852
caseLambda match {
28532853
case caseLambda: HKTypeLambda =>
28542854
val instances = paramInstances(new Array(caseLambda.paramNames.length), pat)
2855-
instantiateParams(instances)(body)
2855+
instantiateParams(instances)(body).simplified
28562856
case _ =>
28572857
body
28582858
}

compiler/test-resources/repl/i5218

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ val tuple: (Int, String, Long) = (1,2,3)
33
scala> 0.0 *: tuple
44
val res0: (Double, Int, String, Long) = (0.0,1,2,3)
55
scala> tuple ++ tuple
6-
val res1: Int *: String *: Long *:
7-
scala.Tuple.Concat[EmptyTuple.type, tuple.type] = (1,2,3,1,2,3)
6+
val res1: Int *: String *: Long *: tuple.type = (1,2,3,1,2,3)

compiler/test/dotc/pos-test-pickling.blacklist

+1-8
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,13 @@ seqtype-cycle
2525
i939.scala
2626

2727
# Match types
28-
typelevel0.scala
29-
matchtype.scala
30-
6322.scala
31-
i7087.scala
32-
i7868.scala
3328
i7872.scala
34-
6709.scala
35-
6687.scala
3629
i11236.scala
3730
i11247.scala
3831
i11250
3932
i9999.scala
40-
i12127.scala
4133
8649.scala
34+
12093.scala
4235

4336
# Opaque type
4437
i5720.scala
File renamed without changes.

tests/pos/12093.scala

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import scala.compiletime.ops.int.{`*`, +}
2+
3+
// HList
4+
sealed trait Shape
5+
final case class #:[H <: Int & Singleton, T <: Shape](head: H, tail: T) extends Shape
6+
case object Ø extends Shape
7+
type Ø = Ø.type
8+
9+
// Reduce
10+
def reduce[T, S <: Shape, A <: Shape](shape: S, axes: A): Reduce[S, A, 0] = ???
11+
type Reduce[S, Axes <: Shape, I <: Int] <: Shape = S match {
12+
case head #: tail => Contains[Axes, I] match {
13+
case true => Reduce[tail, Remove[Axes, I], I + 1]
14+
case false => head #: Reduce[tail, Axes, I + 1]
15+
}
16+
case Ø => Axes match {
17+
case Ø => Ø
18+
// otherwise, do not reduce further
19+
}
20+
}
21+
type Contains[Haystack <: Shape, Needle <: Int] <: Boolean = Haystack match {
22+
case Ø => false
23+
case head #: tail => head match {
24+
case Needle => true
25+
case _ => Contains[tail, Needle]
26+
}
27+
}
28+
type Remove[From <: Shape, Value <: Int] <: Shape = From match {
29+
case Ø => Ø
30+
case head #: tail => head match {
31+
case Value => Remove[tail, Value]
32+
case _ => head #: Remove[tail, Value]
33+
}
34+
}
35+
36+
// Reshape
37+
def reshape[From <: Shape, To <: Shape](from: From, to: To)
38+
(using ev: NumElements[From] =:= NumElements[To]): To = ???
39+
type NumElements[X <: Shape] <: Int = X match {
40+
case Ø => 1
41+
case head #: tail => head * NumElements[tail]
42+
}
43+
44+
// Test cases
45+
val input = #:(25, #:(256, #:(256, #:(3, Ø))))
46+
val reduced = reduce(input, #:(3, #:(1, #:(2, Ø))))
47+
val reshaped: 5 #: 5 #: Ø = reshape(reduced, #:(5, #:(5, Ø)))
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)