Skip to content

Commit c9a296d

Browse files
committed
Fix >:> comparison of compiletime applied types
1 parent f634215 commit c9a296d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
10151015
false
10161016
}
10171017

1018-
/** Compare `tp` of form `S[arg]` with `other`, via ">:>` if fromBelow is true, "<:<" otherwise.
1018+
/** Compare `tp` of form `S[arg]` with `other`, via ">:>" if fromBelow is true, "<:<" otherwise.
10191019
* If `arg` is a Nat constant `n`, proceed with comparing `n + 1` and `other`.
10201020
* Otherwise, if `other` is a Nat constant `n`, proceed with comparing `arg` and `n - 1`.
10211021
*/
@@ -1037,11 +1037,15 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
10371037
case _ => false
10381038
}
10391039

1040+
/** Compare `tp` of form `tycon[...args]`, where `tycon` is a scala.compiletime type,
1041+
* with `other` via ">:>" if fromBelow is true, "<:<" otherwise.
1042+
* Delegates to compareS if `tycon` is scala.compiletime.S. Otherwise, constant folds if possible.
1043+
*/
10401044
def compareCompiletimeAppliedType(tp: AppliedType, other: Type, fromBelow: Boolean): Boolean = {
10411045
if (defn.isCompiletime_S(tp.tycon.typeSymbol)) compareS(tp, other, fromBelow)
10421046
else {
10431047
val reduced = tp.tryCompiletimeConstantFold.getOrElse(tp.superType)
1044-
recur(reduced, other)
1048+
if (fromBelow) recur(other, reduced) else recur(reduced, other)
10451049
}
10461050
}
10471051

tests/neg/singleton-ops.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ object Test {
55
summon[1763 =:= 41 * 43]
66
summon[2 + 2 =:= 3] // error
77
summon[29 * 31 =:= 900] // error
8+
summon[Any <:< Int + 1] // error
9+
summon[Int + 1 <:< Any]
810

911
val a: Int + Int = 3
1012
val c: 1 + Int = 2

0 commit comments

Comments
 (0)