Skip to content

Commit a12c365

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

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
@@ -3344,6 +3344,13 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
33443344

33453345
case _ =>
33463346
false
3347+
3348+
case MatchTypeCasePattern.CompileTimeS(argPattern) =>
3349+
natValue(scrut) match
3350+
case Some(scrutValue) if scrutValue > 0 =>
3351+
rec(argPattern, ConstantType(Constant(scrutValue - 1)), variance, scrutIsWidenedAbstract)
3352+
case _ =>
3353+
false
33473354
end rec
33483355

33493356
// 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
@@ -5065,6 +5065,7 @@ object Types {
50655065
case Capture(num: Int, isWildcard: Boolean)
50665066
case TypeTest(tpe: Type)
50675067
case BaseTypeTest(classType: TypeRef, argPatterns: List[MatchTypeCasePattern], needsConcreteScrut: Boolean)
5068+
case CompileTimeS(argPattern: MatchTypeCasePattern)
50685069

50695070
def isTypeTest: Boolean =
50705071
this.isInstanceOf[TypeTest]
@@ -5129,6 +5130,14 @@ object Types {
51295130
(argPattern, tparam) => tparam.paramVarianceSign != 0 && argPattern.needsConcreteScrutInVariantPos
51305131
}
51315132
MatchTypeCasePattern.BaseTypeTest(tycon, argPatterns1, needsConcreteScrut)
5133+
else if defn.isCompiletime_S(tyconSym) && args.sizeIs == 1 then
5134+
val argPattern = rec(args.head, variance)
5135+
if argPattern == null then
5136+
null
5137+
else if argPattern.isTypeTest then
5138+
MatchTypeCasePattern.TypeTest(pat)
5139+
else
5140+
MatchTypeCasePattern.CompileTimeS(argPattern)
51325141
else
51335142
null
51345143

0 commit comments

Comments
 (0)