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
1022
1022
def compareS (tp : AppliedType , other : Type , fromBelow : Boolean ): Boolean = tp.args match {
1023
1023
case arg :: Nil =>
1024
1024
natValue(arg) match {
1025
- case Some (n) =>
1025
+ case Some (n) if n != Int . MaxValue =>
1026
1026
val succ = ConstantType (Constant (n + 1 ))
1027
1027
if (fromBelow) recur(other, succ) else recur(succ, other)
1028
1028
case none =>
Original file line number Diff line number Diff line change @@ -3598,7 +3598,8 @@ object Types {
3598
3598
if (defn.isCompiletime_S(tycon.symbol) && args.length == 1 )
3599
3599
trace(i " normalize S $this" , typr, show = true ) {
3600
3600
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 ))
3602
3603
case none => tryMatchAlias
3603
3604
}
3604
3605
}
Original file line number Diff line number Diff line change @@ -52,5 +52,15 @@ package object compiletime {
52
52
*/
53
53
inline def summonFrom [T ](f : Nothing => T ) <: T = ???
54
54
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
56
66
}
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