Skip to content

Commit b458372

Browse files
committed
Add singleton ops tests suggested by review
1 parent 30d0a8e commit b458372

5 files changed

+47
-27
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import scala.compiletime.int._
2+
3+
object Test {
4+
type Max2[A <: Int, B <: Int] <: Int = (A < B) match {
5+
case true => B
6+
case false => A
7+
}
8+
val t0: Max2[-1, 10] = 10
9+
val t1: Max2[4, 2] = 4
10+
val t2: Max2[2, 2] = 1 // error
11+
val t3: Max2[-1, -1] = 0 // error
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import scala.compiletime.int._
2+
3+
object Test {
4+
type GCD[A <: Int, B <: Int] <: Int = B match {
5+
case 0 => A
6+
case _ => GCD[B, A % B]
7+
}
8+
val t0: GCD[10, 0] = 10
9+
val t1: GCD[252, 105] = 21
10+
val t3: GCD[105, 147] = 10 // error
11+
val t4: GCD[1, 1] = -1 // error
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.compiletime.boolean._
2+
3+
object Test {
4+
type Xor[A <: Boolean, B <: Boolean] = (A && ![B]) || (![A] && B)
5+
val t0: Xor[true, true] = false
6+
val t1: Xor[false, true] = true
7+
val t2: Xor[true, false] = false // error
8+
val t3: Xor[false, false] = true // error
9+
}

tests/neg/compiletime-singleton-ops.scala renamed to tests/neg/singleton-ops.scala

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import scala.compiletime.int._
33
import scala.compiletime.boolean._
44

55
object Test {
6+
summon[2 + 3 =:= 6 - 1]
7+
summon[1763 =:= 41 * 43]
8+
summon[2 + 2 =:= 3] // error
9+
summon[29 * 31 =:= 900] // error
10+
611
val t0: 2 + 3 = 5
712
val t1: 2 + 2 = 5 // error
813
val t2: -1 + 1 = 0
@@ -87,31 +92,4 @@ object Test {
8792
val t65: ![false] = true
8893
val t66: ![true] = true // error
8994
val t67: ![false] = false // error
90-
91-
// Test singleton ops in type alias:
92-
type Xor[A <: Boolean, B <: Boolean] = (A && ![B]) || (![A] && B)
93-
val t68: Xor[true, true] = false
94-
val t69: Xor[false, true] = true
95-
val t70: Xor[true, false] = false // error
96-
val t71: Xor[false, false] = true // error
97-
98-
// Test singleton ops in recursive match types:
99-
type GCD[A <: Int, B <: Int] <: Int = B match {
100-
case 0 => A
101-
case _ => GCD[B, A % B]
102-
}
103-
val t72: GCD[10, 0] = 10
104-
val t73: GCD[252, 105] = 21
105-
val t74: GCD[105, 147] = 10 // error
106-
val t75: GCD[1, 1] = -1 // error
107-
108-
// Test singleton ops in match type scrutinee:
109-
type Max2[A <: Int, B <: Int] <: Int = (A < B) match {
110-
case true => B
111-
case false => A
112-
}
113-
val t76: Max[-1, 10] = 10
114-
val t77: Max[4, 2] = 4
115-
val t78: Max[2, 2] = 1 // error
116-
val t79: Max[-1, -1] = 0 // error
11795
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.compiletime.int._
2+
import scala.compiletime.boolean._
3+
4+
object Test {
5+
val t0: 1 + 2 * 3 = 7
6+
val t1: (2 * 7 + 1) % 10 = 5
7+
val t3: 1 * 1 + 2 * 2 + 3 * 3 + 4 * 4 = 30
8+
val t4: true && false || true && true || false ^ false = true
9+
}

0 commit comments

Comments
 (0)