Skip to content

Commit 9a59b91

Browse files
committed
add eq/ne extension for AnyRef|Null to Scala3RunTime
1 parent fb618ad commit 9a59b91

File tree

8 files changed

+13
-14
lines changed

8 files changed

+13
-14
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ object Contexts {
401401
def isImportContext: Boolean =
402402
(this ne NoContext)
403403
&& (outer ne NoContext)
404-
&& (this.importInfo nen outer.importInfo)
404+
&& (this.importInfo ne outer.importInfo)
405405

406406
/** Is this a context that introduces a non-empty scope? */
407407
def isNonEmptyScopeContext: Boolean =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class TyperState() {
254254
val toCollect = new mutable.ListBuffer[TypeLambda]
255255
for tvar <- ownedVars do
256256
val tvarState = tvar.owningState.nn.get
257-
assert(tvarState eqn this, s"Inconsistent state in $this: it owns $tvar whose owningState is ${tvarState}")
257+
assert(tvarState eq this, s"Inconsistent state in $this: it owns $tvar whose owningState is ${tvarState}")
258258
assert(!tvar.inst.exists, s"Inconsistent state in $this: it owns $tvar which is already instantiated")
259259
val inst = constraint.instType(tvar)
260260
if inst.exists then

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ object Implicits:
322322
*/
323323
private def isOuterMost = {
324324
val finalImplicits = NoContext.implicits
325-
(this eq finalImplicits) || (outerImplicits eqn finalImplicits)
325+
(this eq finalImplicits) || (outerImplicits eq finalImplicits)
326326
}
327327

328328
private def combineEligibles(ownEligible: List[Candidate], outerEligible: List[Candidate]): List[Candidate] =
@@ -383,7 +383,7 @@ object Implicits:
383383
else {
384384
val outerExcluded = outerImplicits.nn exclude root
385385
if (irefCtx.importInfo.nn.site.termSymbol == root) outerExcluded
386-
else if (outerExcluded eqn outerImplicits) this
386+
else if (outerExcluded eq outerImplicits) this
387387
else new ContextualImplicits(refs, outerExcluded, isImport)(irefCtx)
388388
}
389389
}

compiler/src/dotty/tools/dotc/typer/ImportInfo.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class ImportInfo(symf: Context ?=> Symbol,
218218
case Some(bv) => bv
219219
case None =>
220220
var c = ctx.outer
221-
while c.importInfo eqn ctx.importInfo do c = c.outer
221+
while c.importInfo eq ctx.importInfo do c = c.outer
222222
val cinfo = c.importInfo
223223
(cinfo != null) && cinfo.featureImported(feature)(using c)
224224
)

compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ trait ImportSuggestions:
123123
.filter(lookInside(_))
124124
.flatMap(sym => rootsIn(sym.termRef))
125125
val imported =
126-
if ctx.importInfo eqn ctx.outer.importInfo then Nil
126+
if ctx.importInfo eq ctx.outer.importInfo then Nil
127127
else ctx.importInfo.nn.importSym.info match
128128
case ImportType(expr) => rootsOnPath(expr.tpe)
129129
case _ => Nil

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
434434
if (curImport.nn.unimported ne NoSymbol) unimported += curImport.nn.unimported
435435
if (curOwner.is(Package) && curImport != null && curImport.isRootImport && previous.exists)
436436
previous // no more conflicts possible in this case
437-
else if (isPossibleImport(NamedImport) && (curImport nen outer.importInfo)) {
437+
else if (isPossibleImport(NamedImport) && (curImport ne outer.importInfo)) {
438438
val namedImp = namedImportRef(curImport.uncheckedNN)
439439
if (namedImp.exists)
440440
recurAndCheckNewOrShadowed(namedImp, NamedImport, ctx)(using outer)

compiler/src/dotty/tools/package.scala

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ package object tools {
3636
if x == null then None else Some(x.asInstanceOf[T])
3737
end extension
3838

39-
/** Nullable eq and ne. */
40-
extension [T <: AnyRef](x: T | Null)
41-
inline def eqn (y: T | Null) =
42-
x.asInstanceOf[AnyRef] eq y.asInstanceOf[AnyRef]
43-
44-
inline def nen(y: T | Null): Boolean = !eqn(y)
45-
4639
object resultWrapper {
4740
opaque type WrappedResult[T] = T
4841
private[tools] def unwrap[T](x: WrappedResult[T]): T = x

library/src/scala/runtime/Scala3RunTime.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ object Scala3RunTime:
1919
if (isNull) throw new NullPointerException("tried to cast away nullability, but value is null")
2020
else x.asInstanceOf[x.type & T]
2121

22+
extension (inline x: AnyRef | Null)
23+
inline def eq(inline y: AnyRef | Null): Boolean =
24+
x.asInstanceOf[AnyRef] eq y.asInstanceOf[AnyRef]
25+
inline def ne(inline y: AnyRef | Null): Boolean =
26+
!(x eq y)
27+
2228
end Scala3RunTime

0 commit comments

Comments
 (0)