Skip to content

Commit e2b0de0

Browse files
committed
rename bitwise and/or compiletime int operations
1 parent 05cb10f commit e2b0de0

File tree

6 files changed

+51
-49
lines changed

6 files changed

+51
-49
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ class Definitions {
955955
tpnme.Plus, tpnme.Minus, tpnme.Times, tpnme.Div, tpnme.Mod,
956956
tpnme.Lt, tpnme.Gt, tpnme.Ge, tpnme.Le,
957957
tpnme.Abs, tpnme.Negate, tpnme.Min, tpnme.Max, tpnme.ToString,
958-
tpnme.Xor, tpnme.AND, tpnme.OR, tpnme.ASR, tpnme.LSL, tpnme.LSR
958+
tpnme.Xor, tpnme.BitwiseAnd, tpnme.BitwiseOr, tpnme.ASR, tpnme.LSL, tpnme.LSR
959959
)
960960
private val compiletimePackageBooleanTypes: Set[Name] = Set(tpnme.Not, tpnme.Xor, tpnme.And, tpnme.Or)
961961
private val compiletimePackageStringTypes: Set[Name] = Set(tpnme.Plus)

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

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -208,27 +208,29 @@ object StdNames {
208208
final val IOOBException: N = "IndexOutOfBoundsException"
209209
final val FunctionXXL: N = "FunctionXXL"
210210

211-
final val Abs: N = "Abs"
212-
final val And: N = "&&"
213-
final val Div: N = "/"
214-
final val Equals: N = "=="
215-
final val Ge: N = ">="
216-
final val Gt: N = ">"
217-
final val Le: N = "<="
218-
final val Lt: N = "<"
219-
final val Max: N = "Max"
220-
final val Min: N = "Min"
221-
final val Minus: N = "-"
222-
final val Mod: N = "%"
223-
final val Negate: N = "Negate"
224-
final val Not: N = "!"
225-
final val NotEquals: N = "!="
226-
final val Or: N = "||"
227-
final val Plus: N = "+"
228-
final val S: N = "S"
229-
final val Times: N = "*"
230-
final val ToString: N = "ToString"
231-
final val Xor: N = "^"
211+
final val Abs: N = "Abs"
212+
final val And: N = "&&"
213+
final val BitwiseAnd: N = "BitwiseAnd"
214+
final val BitwiseOr: N = "BitwiseOr"
215+
final val Div: N = "/"
216+
final val Equals: N = "=="
217+
final val Ge: N = ">="
218+
final val Gt: N = ">"
219+
final val Le: N = "<="
220+
final val Lt: N = "<"
221+
final val Max: N = "Max"
222+
final val Min: N = "Min"
223+
final val Minus: N = "-"
224+
final val Mod: N = "%"
225+
final val Negate: N = "Negate"
226+
final val Not: N = "!"
227+
final val NotEquals: N = "!="
228+
final val Or: N = "||"
229+
final val Plus: N = "+"
230+
final val S: N = "S"
231+
final val Times: N = "*"
232+
final val ToString: N = "ToString"
233+
final val Xor: N = "^"
232234

233235
final val ClassfileAnnotation: N = "ClassfileAnnotation"
234236
final val ClassManifest: N = "ClassManifest"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3843,8 +3843,8 @@ object Types {
38433843
case tpnme.Ge if nArgs == 2 => constantFold2(intValue, _ >= _)
38443844
case tpnme.Le if nArgs == 2 => constantFold2(intValue, _ <= _)
38453845
case tpnme.Xor if nArgs == 2 => constantFold2(intValue, _ ^ _)
3846-
case tpnme.AND if nArgs == 2 => constantFold2(intValue, _ & _)
3847-
case tpnme.OR if nArgs == 2 => constantFold2(intValue, _ | _)
3846+
case tpnme.BitwiseAnd if nArgs == 2 => constantFold2(intValue, _ & _)
3847+
case tpnme.BitwiseOr if nArgs == 2 => constantFold2(intValue, _ | _)
38483848
case tpnme.ASR if nArgs == 2 => constantFold2(intValue, _ >> _)
38493849
case tpnme.LSL if nArgs == 2 => constantFold2(intValue, _ << _)
38503850
case tpnme.LSR if nArgs == 2 => constantFold2(intValue, _ >>> _)

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,6 @@ package object ops {
8989
*/
9090
@infix type >>>[X <: Int, Y <: Int] <: Int
9191

92-
/** Bitwise and of `X` and `Y`.
93-
* ```scala
94-
* val and1: 4 & 4 = 4
95-
* val and2: 10 & 5 = 0
96-
* ```
97-
*/
98-
@infix type &[X <: Int, Y <: Int] <: Int
99-
100-
/** Bitwise or of `X` and `Y`.
101-
* ```scala
102-
* val or: 10 | 11 = 11
103-
* ```
104-
*/
105-
@infix type |[X <: Int, Y <: Int] <: Int
106-
10792
/** Bitwise xor of `X` and `Y`.
10893
* ```scala
10994
* val xor: 10 ^ 30 = 20
@@ -143,6 +128,21 @@ package object ops {
143128
*/
144129
@infix type <=[X <: Int, Y <: Int] <: Boolean
145130

131+
/** Bitwise and of `X` and `Y`.
132+
* ```scala
133+
* val and1: BitwiseAnd[4, 4] = 4
134+
* val and2: BitwiseAnd[10, 5] = 0
135+
* ```
136+
*/
137+
type BitwiseAnd[X <: Int, Y <: Int] <: Int
138+
139+
/** Bitwise or of `X` and `Y`.
140+
* ```scala
141+
* val or: BitwiseOr[10, 11] = 11
142+
* ```
143+
*/
144+
type BitwiseOr[X <: Int, Y <: Int] <: Int
145+
146146
/** Absolute value of an `Int` singleton type.
147147
* ```scala
148148
* val abs: Abs[-1] = 1

tests/neg/singleton-ops-int.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ object Test {
7878
val t54: -1 ^ -2 = 1
7979
val t55: -1 ^ -3 = 1 // error
8080

81-
val t56: 1 | 2 = 3
82-
val t57: 10 | 12 = 13 // error
83-
val t58: -11 | 12 = -3
84-
val t59: -111 | -10 = 0 // error
85-
86-
val t60: 1 & 1 = 1
87-
val t61: 1 & 2 = 0
88-
val t62: -1 & -3 = 3 // error
89-
val t63: -1 & -1 = 1 // error
81+
val t56: BitwiseOr[1, 2] = 3
82+
val t57: BitwiseOr[10, 12] = 13 // error
83+
val t58: BitwiseOr[-11, 12] = -3
84+
val t59: BitwiseOr[-111, -10] = 0 // error
85+
86+
val t60: BitwiseAnd[1, 1] = 1
87+
val t61: BitwiseAnd[1, 2] = 0
88+
val t62: BitwiseAnd[-1, -3] = 3 // error
89+
val t63: BitwiseAnd[-1, -1] = 1 // error
9090

9191
val t64: 1 << 1 = 2
9292
val t65: 1 << 2 = 4

tests/pos/singleton-ops-composition.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ object Test {
66
val t1: (2 * 7 + 1) % 10 = 5
77
val t3: 1 * 1 + 2 * 2 + 3 * 3 + 4 * 4 = 30
88
val t4: true && false || true && true || false ^ false = true
9-
val t5: 100 << 2 >>> 2 >> 2 ^^ 3 | (7 & 7) = 31
9+
val t5: BitwiseOr[100 << 2 >>> 2 >> 2 ^^ 3, BitwiseAnd[7, 7]] = 31
1010
}

0 commit comments

Comments
 (0)