Skip to content

Commit 9f36146

Browse files
committed
Revert "Add Singleton upperbound to primitive type operations"
This reverts commit 3d5017a.
1 parent 0f14ad3 commit 9f36146

File tree

7 files changed

+33
-33
lines changed

7 files changed

+33
-33
lines changed

docs/docs/reference/metaprogramming/inline.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,9 @@ match type can dispatch to the correct implementation:
462462
import scala.compiletime.ops._
463463
import scala.annotation.infix
464464

465-
@infix type +[X <: Int & Singleton | String & Singleton, Y <: Int & Singleton | String & Singleton] = (X, Y) match {
466-
case (Int & Singleton, Int & Singleton) => int.+[X, Y]
467-
case (String & Singleton, String & Singleton) => string.+[X, Y]
465+
@infix type +[X <: Int | String, Y <: Int | String] = (X, Y) match {
466+
case (Int, Int) => int.+[X, Y]
467+
case (String, String) => string.+[X, Y]
468468
}
469469

470470
val concat: "a" + "b" = "ab"

library/src/scala/compiletime/ops/package.scala

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ package object ops {
1111
* val eq3: "1" == "1" = true
1212
* ```
1313
*/
14-
@infix type ==[X <: AnyVal & Singleton, Y <: AnyVal & Singleton] <: Boolean & Singleton
14+
@infix type ==[X <: AnyVal, Y <: AnyVal] <: Boolean
1515

1616
/** Inequality comparison of two singleton types.
1717
* ```scala
@@ -20,7 +20,7 @@ package object ops {
2020
* val eq3: "1" != "1" = false
2121
* ```
2222
*/
23-
@infix type !=[X <: AnyVal & Singleton, Y <: AnyVal & Singleton] <: Boolean & Singleton
23+
@infix type !=[X <: AnyVal, Y <: AnyVal] <: Boolean
2424
}
2525

2626
object string {
@@ -29,7 +29,7 @@ package object ops {
2929
* val hello: "hello " + "world" = "hello world"
3030
* ```
3131
*/
32-
@infix type +[X <: String & Singleton, Y <: String & Singleton] <: String & Singleton
32+
@infix type +[X <: String, Y <: String] <: String
3333
}
3434

3535
object int {
@@ -38,103 +38,103 @@ package object ops {
3838
* val sum: 2 + 2 = 4
3939
* ```
4040
*/
41-
@infix type +[X <: Int & Singleton, Y <: Int & Singleton] <: Int & Singleton
41+
@infix type +[X <: Int, Y <: Int] <: Int
4242

4343
/** Subtraction of two `Int` singleton types.
4444
* ```scala
4545
* val sub: 4 - 2 = 2
4646
* ```
4747
*/
48-
@infix type -[X <: Int & Singleton, Y <: Int & Singleton] <: Int & Singleton
48+
@infix type -[X <: Int, Y <: Int] <: Int
4949

5050
/** Multiplication of two `Int` singleton types.
5151
* ```scala
5252
* val mul: 4 * 2 = 8
5353
* ```
5454
*/
55-
@infix type *[X <: Int & Singleton, Y <: Int & Singleton] <: Int & Singleton
55+
@infix type *[X <: Int, Y <: Int] <: Int
5656

5757
/** Integer division of two `Int` singleton types.
5858
* ```scala
5959
* val div: 5 / 2 = 2
6060
* ```
6161
*/
62-
@infix type /[X <: Int & Singleton, Y <: Int & Singleton] <: Int & Singleton
62+
@infix type /[X <: Int, Y <: Int] <: Int
6363

6464
/** Remainder of the division of `X` by `Y`.
6565
* ```scala
6666
* val mod: 5 % 2 = 1
6767
* ```
6868
*/
69-
@infix type %[X <: Int & Singleton, Y <: Int & Singleton] <: Int & Singleton
69+
@infix type %[X <: Int, Y <: Int] <: Int
7070

7171
/** Less-than comparison of two `Int` singleton types.
7272
* ```scala
7373
* val lt1: 4 < 2 = false
7474
* val lt2: 2 < 4 = true
7575
* ```
7676
*/
77-
@infix type <[X <: Int & Singleton, Y <: Int & Singleton] <: Boolean & Singleton
77+
@infix type <[X <: Int, Y <: Int] <: Boolean
7878

7979
/** Greater-than comparison of two `Int` singleton types.
8080
* ```scala
8181
* val gt1: 4 > 2 = true
8282
* val gt2: 2 > 2 = false
8383
* ```
8484
*/
85-
@infix type >[X <: Int & Singleton, Y <: Int & Singleton] <: Boolean & Singleton
85+
@infix type >[X <: Int, Y <: Int] <: Boolean
8686

8787
/** Greater-or-equal comparison of two `Int` singleton types.
8888
* ```scala
8989
* val ge1: 4 >= 2 = true
9090
* val ge2: 2 >= 3 = false
9191
* ```
9292
*/
93-
@infix type >=[X <: Int & Singleton, Y <: Int & Singleton] <: Boolean & Singleton
93+
@infix type >=[X <: Int, Y <: Int] <: Boolean
9494

9595
/** Less-or-equal comparison of two `Int` singleton types.
9696
* ```scala
9797
* val lt1: 4 <= 2 = false
9898
* val lt2: 2 <= 2 = true
9999
* ```
100100
*/
101-
@infix type <=[X <: Int & Singleton, Y <: Int & Singleton] <: Boolean & Singleton
101+
@infix type <=[X <: Int, Y <: Int] <: Boolean
102102

103103
/** Absolute value of an `Int` singleton type.
104104
* ```scala
105105
* val abs: Abs[-1] = 1
106106
* ```
107107
*/
108-
type Abs[X <: Int & Singleton] <: Int & Singleton
108+
type Abs[X <: Int] <: Int
109109

110110
/** Negation of an `Int` singleton type.
111111
* ```scala
112112
* val neg1: Neg[-1] = 1
113113
* val neg2: Neg[1] = -1
114114
* ```
115115
*/
116-
type Negate[X <: Int & Singleton] <: Int & Singleton
116+
type Negate[X <: Int] <: Int
117117

118118
/** Minimum of two `Int` singleton types.
119119
* ```scala
120120
* val min: Min[-1, 1] = -1
121121
* ```
122122
*/
123-
type Min[X <: Int & Singleton, Y <: Int & Singleton] <: Int & Singleton
123+
type Min[X <: Int, Y <: Int] <: Int
124124

125125
/** Maximum of two `Int` singleton types.
126126
* ```scala
127127
* val abs: Abs[-1] = 1
128128
* ```
129129
*/
130-
type Max[X <: Int & Singleton, Y <: Int & Singleton] <: Int & Singleton
130+
type Max[X <: Int, Y <: Int] <: Int
131131

132132
/** String conversion of an `Int` singleton type.
133133
* ```scala
134134
* val abs: ToString[1] = "1"
135135
* ```
136136
*/
137-
type ToString[X <: Int & Singleton] <: String & Singleton
137+
type ToString[X <: Int] <: String
138138
}
139139

140140
object boolean {
@@ -145,30 +145,30 @@ package object ops {
145145
* val notTrue: ![true] = false
146146
* ```
147147
*/
148-
type ![X <: Boolean & Singleton] <: Boolean & Singleton
148+
type ![X <: Boolean] <: Boolean
149149

150150
/** Exclusive disjunction of two `Boolean` singleton types.
151151
* ```scala
152152
* val a: true ^ true = false
153153
* val b: false ^ true = true
154154
* ```
155155
*/
156-
@infix type ^[X <: Boolean & Singleton, Y <: Boolean & Singleton] <: Boolean & Singleton
156+
@infix type ^[X <: Boolean, Y <: Boolean] <: Boolean
157157

158158
/** Conjunction of two `Boolean` singleton types.
159159
* ```scala
160160
* val a: true && true = true
161161
* val b: false && true = false
162162
* ```
163163
*/
164-
@infix type &&[X <: Boolean & Singleton, Y <: Boolean & Singleton] <: Boolean & Singleton
164+
@infix type &&[X <: Boolean, Y <: Boolean] <: Boolean
165165

166166
/** Disjunction of two `Boolean` singleton types.
167167
* ```scala
168168
* val a: true || false = true
169169
* val b: false || false = false
170170
* ```
171171
*/
172-
@infix type ||[X <: Boolean & Singleton, Y <: Boolean & Singleton] <: Boolean & Singleton
172+
@infix type ||[X <: Boolean, Y <: Boolean] <: Boolean
173173
}
174174
}

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.3.6
1+
sbt.version=1.3.6

tests/neg/singleton-ops-match-type-scrutinee.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import scala.compiletime.ops.int._
22

33
object Test {
4-
type Max2[A <: Int & Singleton, B <: Int & Singleton] <: Int & Singleton = (A < B) match {
4+
type Max2[A <: Int, B <: Int] <: Int = (A < B) match {
55
case true => B
66
case false => A
77
}

tests/neg/singleton-ops-recursive-match-type.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import scala.compiletime.ops.int._
22

33
object Test {
4-
type GCD[A <: Int & Singleton, B <: Int & Singleton] <: Int & Singleton = B match {
4+
type GCD[A <: Int, B <: Int] <: Int = B match {
55
case 0 => A
66
case _ => GCD[B, A % B]
77
}

tests/neg/singleton-ops-type-alias.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import scala.compiletime.ops.boolean._
22

33
object Test {
4-
type Xor[A <: Boolean & Singleton, B <: Boolean & Singleton] = (A && ![B]) || (![A] && B)
4+
type Xor[A <: Boolean, B <: Boolean] = (A && ![B]) || (![A] && B)
55
val t0: Xor[true, true] = false
66
val t1: Xor[false, true] = true
77
val t2: Xor[true, false] = false // error

tests/pos/singleton-ops-dispatch.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import scala.compiletime.ops._
22
import scala.annotation.infix
33

44
object Test {
5-
@infix type +[X <: Int & Singleton | String & Singleton, Y <: Int & Singleton | String & Singleton] = (X, Y) match {
6-
case (Int & Singleton, Int & Singleton) => int.+[X, Y]
7-
case (String & Singleton, String & Singleton) => string.+[X, Y]
8-
case (String & Singleton, Int & Singleton) => string.+[X, int.ToString[Y]]
9-
case (Int & Singleton, String & Singleton) => string.+[int.ToString[X], Y]
5+
@infix type +[X <: Int | String, Y <: Int | String] = (X, Y) match {
6+
case (Int, Int) => int.+[X, Y]
7+
case (String, String) => string.+[X, Y]
8+
case (String, Int) => string.+[X, int.ToString[Y]]
9+
case (Int, String) => string.+[int.ToString[X], Y]
1010
}
1111

1212
val t0: "a" + 1 = "a1"

0 commit comments

Comments
 (0)