Skip to content

Commit 223be76

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

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
@@ -5059,6 +5059,7 @@ object Types {
50595059
case Capture(num: Int, isWildcard: Boolean)
50605060
case TypeTest(tpe: Type)
50615061
case BaseTypeTest(classType: TypeRef, argPatterns: List[MatchTypeCasePattern], needsConcreteScrut: Boolean)
5062+
case CompileTimeS(argPattern: MatchTypeCasePattern)
50625063

50635064
def isTypeTest: Boolean =
50645065
this.isInstanceOf[TypeTest]
@@ -5123,6 +5124,14 @@ object Types {
51235124
(argPattern, tparam) => tparam.paramVarianceSign != 0 && argPattern.needsConcreteScrutInVariantPos
51245125
}
51255126
MatchTypeCasePattern.BaseTypeTest(tycon, argPatterns1, needsConcreteScrut)
5127+
else if defn.isCompiletime_S(tyconSym) && args.sizeIs == 1 then
5128+
val argPattern = rec(args.head, variance)
5129+
if argPattern == null then
5130+
null
5131+
else if argPattern.isTypeTest then
5132+
MatchTypeCasePattern.TypeTest(pat)
5133+
else
5134+
MatchTypeCasePattern.CompileTimeS(argPattern)
51265135
else
51275136
null
51285137

0 commit comments

Comments
 (0)