From 0b7c5990b43b235df5931b8bc1383e7540a64f83 Mon Sep 17 00:00:00 2001 From: odersky Date: Sun, 5 Jun 2022 15:28:09 +0200 Subject: [PATCH] Handle Range cases when reducing match types Fixes #15362 --- .../dotty/tools/dotc/core/TypeComparer.scala | 2 ++ compiler/src/dotty/tools/dotc/core/Types.scala | 2 +- tests/neg/i15362.scala | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i15362.scala diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 134a5006b887..c07e8bc51790 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -2912,6 +2912,8 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) { case cas: HKTypeLambda => caseLambda = constrained(cas) caseLambda.resultType + case _: Range => + return Some(NoType) case _ => cas } diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 8b9f8690604e..d9f423575a46 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -5989,7 +5989,7 @@ object Types { /** A range of possible types between lower bound `lo` and upper bound `hi`. * Only used internally in `ApproximatingTypeMap`. */ - private case class Range(lo: Type, hi: Type) extends UncachedGroundType { + private[core] case class Range(lo: Type, hi: Type) extends UncachedGroundType { assert(!lo.isInstanceOf[Range]) assert(!hi.isInstanceOf[Range]) diff --git a/tests/neg/i15362.scala b/tests/neg/i15362.scala new file mode 100644 index 000000000000..2d30cd92e6d4 --- /dev/null +++ b/tests/neg/i15362.scala @@ -0,0 +1,17 @@ +import scala.compiletime.* +import scala.compiletime.ops.int.* + +abstract sealed class HList : + def ::[H](head: H): HNonEmpty[H, this.type] = HNonEmpty(head, this) + +case object HNil extends HList +case class HNonEmpty[H, T <: HList](head: H, tail: T) extends HList : + type Elem[N <: Int] = + N match + case 0 => H + case S[n1] => Elem[n1] + + inline def apply[N <: Int](n: N): Elem[N] = + n match + case _: 0 => head + case _: S[n1] => tail.asInstanceOf[HNonEmpty[?, ?]].apply(constValue[n1]) // error