Skip to content

Fix #9890: dealias before normalizing match type scrutinee #10559

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

Closed
wants to merge 4 commits into from
Closed
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 @@ -1257,7 +1257,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
val savedSuccessCount = successCount
try
recCount += 1
if recCount >= Config.LogPendingSubTypesThreshold then monitored = true
if recCount >= Config.LogPendingSubTypesThreshold && !ctx.settings.YnoDeepSubtypes.value then monitored = true
val result = if monitored then monitoredIsSubType else firstTry
recCount -= 1
if !result then
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4490,7 +4490,7 @@ object Types {
myReduced =
trace(i"reduce match type $this $hashCode", typr, show = true) {
def matchCases(cmp: TrackingTypeComparer): Type =
try cmp.matchCases(scrutinee.normalized, cases)
try cmp.matchCases(scrutinee.dealias.normalized, cases)
catch case ex: Throwable =>
handleRecursive("reduce type ", i"$scrutinee match ...", ex)
finally updateReductionContext(cmp.footprint)
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotc/pos-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ i7872.scala
6687.scala
i11236.scala
i11247.scala
9890.scala

# Opaque type
i5720.scala
Expand Down
49 changes: 49 additions & 0 deletions tests/pos/9890.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
object Test {
import scala.compiletime.ops.int._

trait x

type Range[Min <: Int, Max <: Int] <: Tuple = Min match {
case Max => EmptyTuple
case _ => Min *: Range[Min + 1, Max]
}

type TupleMap[Tup <: Tuple, Bound, F[_ <: Bound]] <: Tuple = Tup match {
case EmptyTuple => EmptyTuple
case h *: t => F[h] *: TupleMap[t, Bound, F]
}
type TupleDedup[Tup <: Tuple, Mask] <: Tuple = Tup match {
case EmptyTuple => EmptyTuple
case h *: t => h match {
case Mask => TupleDedup[t, Mask]
case _ => h *: TupleDedup[t, h | Mask]
}
}

type CoordToPos[r <: Int, c <: Int] = r * 9 + c
type Cell[r <: Int, c <: Int, Board <: Tuple] = Tuple.Elem[Board, CoordToPos[r, c]]
type Col[c <: Int, Board <: Tuple] = TupleMap[Range[0, 9], Int, [r <: Int] =>> Cell[r, c, Board]]

type ColFromPos[Pos <: Int] = Pos % 9

type Sudoku1 = (
x, x, x, x, 1, x, 4, x, 6,
8, x, 1, 6, 2, x, x, x, 9,
x, 3, x, x, x, 9, x, 2, x,

5, x, 9, 1, 3, x, x, 6, x,
x, 6, x, 9, x, 2, x, 4, x,
x, 2, x, x, 6, 7, 8, x, 5,

x, 9, x, 5, x, x, x, 3, x,
3, x, x, x, 4, 6, 9, x, 7,
6, x, 7, x, 9, x, x, x, x,
)

//compiles fine
summon[Col[ColFromPos[0], Sudoku1] =:= (x, 8, x, 5, x, x, x, 3, 6)]

summon[TupleDedup[(x, 8, x, 5, x, x, x, 3, 6), Nothing] =:= (x, 8, 5, 3, 6)]
//but this doesn't
summon[TupleDedup[Col[ColFromPos[0], Sudoku1], Nothing] =:= (x, 8, 5, 3, 6)]
}