Skip to content

Commit cc41d48

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

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

33573357
case _ =>
33583358
false
3359+
3360+
case MatchTypeCasePattern.CompileTimeS(argPattern) =>
3361+
natValue(scrut) match
3362+
case Some(scrutValue) if scrutValue > 0 =>
3363+
rec(argPattern, ConstantType(Constant(scrutValue - 1)), variance, scrutIsWidenedAbstract)
3364+
case _ =>
3365+
false
33593366
end rec
33603367

33613368
// 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
@@ -5092,6 +5092,7 @@ object Types extends TypeUtils {
50925092
case Capture(num: Int, isWildcard: Boolean)
50935093
case TypeTest(tpe: Type)
50945094
case BaseTypeTest(classType: TypeRef, argPatterns: List[MatchTypeCasePattern], needsConcreteScrut: Boolean)
5095+
case CompileTimeS(argPattern: MatchTypeCasePattern)
50955096

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

0 commit comments

Comments
 (0)