Skip to content

Commit 8c117c1

Browse files
committed
Move equality singleton ops to scala.compiletime.ops.any
This is more consistent with the other ops, which are also split depending on the type of the argument.
1 parent 2cab591 commit 8c117c1

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ class Definitions {
234234
@tu lazy val CompiletimeTesting_ErrorKind_Parser: Symbol = CompiletimeTesting_ErrorKind.requiredMethod("Parser")
235235
@tu lazy val CompiletimeTesting_ErrorKind_Typer: Symbol = CompiletimeTesting_ErrorKind.requiredMethod("Typer")
236236
@tu lazy val CompiletimeOpsPackageObject: Symbol = ctx.requiredModule("scala.compiletime.ops.package")
237+
@tu lazy val CompiletimeOpsPackageObjectAny: Symbol = ctx.requiredModule("scala.compiletime.ops.package.any")
237238
@tu lazy val CompiletimeOpsPackageObjectInt: Symbol = ctx.requiredModule("scala.compiletime.ops.package.int")
238239
@tu lazy val CompiletimeOpsPackageObjectString: Symbol = ctx.requiredModule("scala.compiletime.ops.package.string")
239240
@tu lazy val CompiletimeOpsPackageObjectBoolean: Symbol = ctx.requiredModule("scala.compiletime.ops.package.boolean")
@@ -902,7 +903,7 @@ class Definitions {
902903
final def isCompiletime_S(sym: Symbol)(implicit ctx: Context): Boolean =
903904
sym.name == tpnme.S && sym.owner == CompiletimePackageObject.moduleClass
904905

905-
private val compiletimePackageTypes: Set[Name] = Set(tpnme.Equals, tpnme.NotEquals)
906+
private val compiletimePackageAnyTypes: Set[Name] = Set(tpnme.Equals, tpnme.NotEquals)
906907
private val compiletimePackageIntTypes: Set[Name] = Set(
907908
tpnme.Plus, tpnme.Minus, tpnme.Times, tpnme.Div, tpnme.Mod,
908909
tpnme.Lt, tpnme.Gt, tpnme.Ge, tpnme.Le,
@@ -913,7 +914,7 @@ class Definitions {
913914

914915
final def isCompiletimeAppliedType(sym: Symbol)(implicit ctx: Context): Boolean = {
915916
def isOpsPackageObjectAppliedType: Boolean =
916-
sym.owner == CompiletimeOpsPackageObject.moduleClass && compiletimePackageTypes.contains(sym.name) ||
917+
sym.owner == CompiletimeOpsPackageObjectAny.moduleClass && compiletimePackageAnyTypes.contains(sym.name) ||
917918
sym.owner == CompiletimeOpsPackageObjectInt.moduleClass && compiletimePackageIntTypes.contains(sym.name) ||
918919
sym.owner == CompiletimeOpsPackageObjectBoolean.moduleClass && compiletimePackageBooleanTypes.contains(sym.name) ||
919920
sym.owner == CompiletimeOpsPackageObjectString.moduleClass && compiletimePackageStringTypes.contains(sym.name)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3643,7 +3643,7 @@ object Types {
36433643
if (owner == defn.CompiletimePackageObject.moduleClass) name match {
36443644
case tpnme.S if nArgs == 1 => constantFold1(natValue, _ + 1)
36453645
case _ => None
3646-
} else if (owner == defn.CompiletimeOpsPackageObject.moduleClass) name match {
3646+
} else if (owner == defn.CompiletimeOpsPackageObjectAny.moduleClass) name match {
36473647
case tpnme.Equals if nArgs == 2 => constantFold2(constValue, _ == _)
36483648
case tpnme.NotEquals if nArgs == 2 => constantFold2(constValue, _ != _)
36493649
case _ => None

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,25 @@ package scala.compiletime
33
import scala.annotation.infix
44

55
package object ops {
6-
/** Equality comparison of two singleton types.
7-
* ```scala
8-
* val eq1: 1 == 1 = true
9-
* val eq2: 1 == "1" = false
10-
* val eq3: "1" == "1" = true
11-
* ```
12-
*/
13-
@infix type ==[X <: AnyVal, Y <: AnyVal] <: Boolean
14-
15-
/** Inequality comparison of two singleton types.
16-
* ```scala
17-
* val eq1: 1 != 1 = false
18-
* val eq2: 1 != "1" = true
19-
* val eq3: "1" != "1" = false
20-
* ```
21-
*/
22-
@infix type !=[X <: AnyVal, Y <: AnyVal] <: Boolean
6+
object any {
7+
/** Equality comparison of two singleton types.
8+
* ```scala
9+
* val eq1: 1 == 1 = true
10+
* val eq2: 1 == "1" = false
11+
* val eq3: "1" == "1" = true
12+
* ```
13+
*/
14+
@infix type ==[X <: AnyVal, Y <: AnyVal] <: Boolean
15+
16+
/** Inequality comparison of two singleton types.
17+
* ```scala
18+
* val eq1: 1 != 1 = false
19+
* val eq2: 1 != "1" = true
20+
* val eq3: "1" != "1" = false
21+
* ```
22+
*/
23+
@infix type !=[X <: AnyVal, Y <: AnyVal] <: Boolean
24+
}
2325

2426
object string {
2527
/** Concatenation of two `String` singleton types.

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

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

33
object Test {
44
val t32: 1 == 1 = true

0 commit comments

Comments
 (0)