Skip to content

Commit c0f95e2

Browse files
committed
Use new specced match types for scala.compiletime.int.S[n].
1 parent 3a2c49e commit c0f95e2

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3348,6 +3348,13 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
33483348

33493349
case _ =>
33503350
false
3351+
3352+
case MatchTypeCasePattern.CompileTimeS(argPattern) =>
3353+
natValue(scrut) match
3354+
case Some(scrutValue) if scrutValue > 0 =>
3355+
rec(argPattern, ConstantType(Constant(scrutValue - 1)), variance, scrutIsWidenedAbstract)
3356+
case _ =>
3357+
false
33513358
end rec
33523359

33533360
// This might not be needed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5093,6 +5093,7 @@ object Types {
50935093
case Capture(num: Int, isWildcard: Boolean)
50945094
case TypeTest(tpe: Type)
50955095
case BaseTypeTest(classType: TypeRef, argPatterns: List[MatchTypeCasePattern], needsConcreteScrut: Boolean)
5096+
case CompileTimeS(argPattern: MatchTypeCasePattern)
50965097

50975098
def isTypeTest: Boolean =
50985099
this.isInstanceOf[TypeTest]
@@ -5157,6 +5158,14 @@ object Types {
51575158
(argPattern, tparam) => tparam.paramVarianceSign != 0 && argPattern.needsConcreteScrutInVariantPos
51585159
}
51595160
MatchTypeCasePattern.BaseTypeTest(tycon, argPatterns1, needsConcreteScrut)
5161+
else if defn.isCompiletime_S(tyconSym) && args.sizeIs == 1 then
5162+
val argPattern = rec(args.head, variance)
5163+
if argPattern == null then
5164+
null
5165+
else if argPattern.isTypeTest then
5166+
MatchTypeCasePattern.TypeTest(pat)
5167+
else
5168+
MatchTypeCasePattern.CompileTimeS(argPattern)
51605169
else
51615170
null
51625171

0 commit comments

Comments
 (0)