Skip to content

Commit 5cd0a9d

Browse files
committed
Fix #6606: Do not compute S on negative Ints
1 parent 1725a67 commit 5cd0a9d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3552,7 +3552,7 @@ object Types {
35523552
if (defn.isCompiletime_S(tycon.symbol) && args.length == 1)
35533553
trace(i"normalize S $this", typr, show = true) {
35543554
args.head.normalized match {
3555-
case ConstantType(Constant(n: Int)) => ConstantType(Constant(n + 1))
3555+
case ConstantType(Constant(n: Int)) if n >= 0 => ConstantType(Constant(n + 1))
35563556
case none => tryMatchAlias
35573557
}
35583558
}

tests/neg/i6606.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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] = n // error

0 commit comments

Comments
 (0)