File tree Expand file tree Collapse file tree 4 files changed +22
-3
lines changed
compiler/src/dotty/tools/dotc/core
library/src/scala/compiletime Expand file tree Collapse file tree 4 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -1022,7 +1022,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
10221022 def compareS (tp : AppliedType , other : Type , fromBelow : Boolean ): Boolean = tp.args match {
10231023 case arg :: Nil =>
10241024 natValue(arg) match {
1025- case Some (n) =>
1025+ case Some (n) if n != Int . MaxValue =>
10261026 val succ = ConstantType (Constant (n + 1 ))
10271027 if (fromBelow) recur(other, succ) else recur(succ, other)
10281028 case none =>
Original file line number Diff line number Diff line change @@ -3598,7 +3598,8 @@ object Types {
35983598 if (defn.isCompiletime_S(tycon.symbol) && args.length == 1 )
35993599 trace(i " normalize S $this" , typr, show = true ) {
36003600 args.head.normalized match {
3601- case ConstantType (Constant (n : Int )) => ConstantType (Constant (n + 1 ))
3601+ case ConstantType (Constant (n : Int )) if n >= 0 && n < Int .MaxValue =>
3602+ ConstantType (Constant (n + 1 ))
36023603 case none => tryMatchAlias
36033604 }
36043605 }
Original file line number Diff line number Diff line change @@ -52,5 +52,15 @@ package object compiletime {
5252 */
5353 inline def summonFrom [T ](f : Nothing => T ) <: T = ???
5454
55- type S [X <: Int ] <: Int
55+ /** Succesor of a natural number where zero is the type 0 and successors are reduced as if the definition was
56+ *
57+ * type S[N <: Int] <: Int = N match {
58+ * case 0 => 1
59+ * case 1 => 2
60+ * case 2 => 3
61+ * ...
62+ * case 2147483646 => 2147483647
63+ * }
64+ */
65+ type S [N <: Int ] <: Int
5666}
Original file line number Diff line number Diff line change 1+ val t0 : Int = 0
2+ val t1 : scala.compiletime.S [- 1 ] = 0 // error
3+ val t2 : scala.compiletime.S [Int ] = 1
4+ val t3 : scala.compiletime.S [Int ] = 0 // error
5+ val t4 : scala.compiletime.S [Int ] = t0 // error
6+
7+ val t5 : scala.compiletime.S [2147483647 ] = - 2147483648 // error
8+ val t6 : scala.compiletime.S [- 2147483648 ] = - 2147483647 // error
You can’t perform that action at this time.
0 commit comments