Skip to content

Fix #12093: Simplify types after parameter instantiation #12356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2834,7 +2834,7 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
caseLambda match {
case caseLambda: HKTypeLambda =>
val instances = paramInstances(new Array(caseLambda.paramNames.length), pat)
instantiateParams(instances)(body)
instantiateParams(instances)(body).simplified
case _ =>
body
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/test-resources/repl/i5218
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ val tuple: (Int, String, Long) = (1,2,3)
scala> 0.0 *: tuple
val res0: (Double, Int, String, Long) = (0.0,1,2,3)
scala> tuple ++ tuple
val res1: Int *: String *: Long *:
scala.Tuple.Concat[EmptyTuple.type, tuple.type] = (1,2,3,1,2,3)
val res1: Int *: String *: Long *: tuple.type = (1,2,3,1,2,3)
9 changes: 1 addition & 8 deletions compiler/test/dotc/pos-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,13 @@ seqtype-cycle
i939.scala

# Match types
typelevel0.scala
matchtype.scala
6322.scala
i7087.scala
i7868.scala
i7872.scala
6709.scala
6687.scala
i11236.scala
i11247.scala
i11250
i9999.scala
i12127.scala
8649.scala
12093.scala

# Opaque type
i5720.scala
Expand Down
File renamed without changes.
47 changes: 47 additions & 0 deletions tests/pos/12093.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import scala.compiletime.ops.int.{`*`, +}

// HList
sealed trait Shape
final case class #:[H <: Int & Singleton, T <: Shape](head: H, tail: T) extends Shape
case object Ø extends Shape
type Ø = Ø.type

// Reduce
def reduce[T, S <: Shape, A <: Shape](shape: S, axes: A): Reduce[S, A, 0] = ???
type Reduce[S, Axes <: Shape, I <: Int] <: Shape = S match {
case head #: tail => Contains[Axes, I] match {
case true => Reduce[tail, Remove[Axes, I], I + 1]
case false => head #: Reduce[tail, Axes, I + 1]
}
case Ø => Axes match {
case Ø => Ø
// otherwise, do not reduce further
}
}
type Contains[Haystack <: Shape, Needle <: Int] <: Boolean = Haystack match {
case Ø => false
case head #: tail => head match {
case Needle => true
case _ => Contains[tail, Needle]
}
}
type Remove[From <: Shape, Value <: Int] <: Shape = From match {
case Ø => Ø
case head #: tail => head match {
case Value => Remove[tail, Value]
case _ => head #: Remove[tail, Value]
}
}

// Reshape
def reshape[From <: Shape, To <: Shape](from: From, to: To)
(using ev: NumElements[From] =:= NumElements[To]): To = ???
type NumElements[X <: Shape] <: Int = X match {
case Ø => 1
case head #: tail => head * NumElements[tail]
}

// Test cases
val input = #:(25, #:(256, #:(256, #:(3, Ø))))
val reduced = reduce(input, #:(3, #:(1, #:(2, Ø))))
val reshaped: 5 #: 5 #: Ø = reshape(reduced, #:(5, #:(5, Ø)))
File renamed without changes.
File renamed without changes.