Skip to content

Commit f8b3515

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

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

33383338
case _ =>
33393339
false
3340+
3341+
case MatchTypeCasePattern.CompileTimeS(argPattern) =>
3342+
natValue(scrut) match
3343+
case Some(scrutValue) if scrutValue != Int.MinValue =>
3344+
rec(argPattern, ConstantType(Constant(scrutValue - 1)), variance, scrutIsWidenedAbstract)
3345+
case _ =>
3346+
false
33403347
end rec
33413348

33423349
// 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)