Skip to content

Commit 1f05711

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

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

33413341
case _ =>
33423342
false
3343+
3344+
case MatchTypeCasePattern.CompileTimeS(argPattern) =>
3345+
natValue(scrut) match
3346+
case Some(scrutValue) if scrutValue != Int.MinValue =>
3347+
rec(argPattern, ConstantType(Constant(scrutValue - 1)), variance, scrutIsWidenedAbstract)
3348+
case _ =>
3349+
false
33433350
end rec
33443351

33453352
// 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
@@ -5062,6 +5062,7 @@ object Types {
50625062
case Capture(num: Int, isWildcard: Boolean)
50635063
case TypeTest(tpe: Type)
50645064
case BaseTypeTest(classType: TypeRef, argPatterns: List[MatchTypeCasePattern], needsConcreteScrut: Boolean)
5065+
case CompileTimeS(argPattern: MatchTypeCasePattern)
50655066

50665067
def isTypeTest: Boolean =
50675068
this.isInstanceOf[TypeTest]
@@ -5126,6 +5127,14 @@ object Types {
51265127
(argPattern, tparam) => tparam.paramVarianceSign != 0 && argPattern.needsConcreteScrutInVariantPos
51275128
}
51285129
MatchTypeCasePattern.BaseTypeTest(tycon, argPatterns1, needsConcreteScrut)
5130+
else if defn.isCompiletime_S(tyconSym) && args.sizeIs == 1 then
5131+
val argPattern = rec(args.head, variance)
5132+
if argPattern == null then
5133+
null
5134+
else if argPattern.isTypeTest then
5135+
MatchTypeCasePattern.TypeTest(pat)
5136+
else
5137+
MatchTypeCasePattern.CompileTimeS(argPattern)
51295138
else
51305139
null
51315140

0 commit comments

Comments
 (0)