Skip to content

Commit df117fc

Browse files
authored
Revert "do not patch the implicit scope of scala.Unit in Scala.js" (#24475)
I'll unfortunately revert this change until we somehow have an actual platform dependent TASTy in the stdlib. Reverts #24405 Closes #24467
2 parents f00bcd8 + 98e28eb commit df117fc

File tree

4 files changed

+10
-72
lines changed

4 files changed

+10
-72
lines changed

compiler/src/dotty/tools/backend/sjs/JSDefinitions.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ final class JSDefinitions()(using Context) {
6969
@threadUnsafe lazy val PseudoUnion_fromTypeConstructorR = PseudoUnionModule.requiredMethodRef("fromTypeConstructor")
7070
def PseudoUnion_fromTypeConstructor(using Context) = PseudoUnion_fromTypeConstructorR.symbol
7171

72+
@threadUnsafe lazy val UnionOpsModuleRef = requiredModuleRef("scala.scalajs.js.internal.UnitOps")
73+
7274
@threadUnsafe lazy val JSArrayType: TypeRef = requiredClassRef("scala.scalajs.js.Array")
7375
def JSArrayClass(using Context) = JSArrayType.symbol.asClass
7476
@threadUnsafe lazy val JSDynamicType: TypeRef = requiredClassRef("scala.scalajs.js.Dynamic")

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,13 @@ trait ImplicitRunInfo:
738738
.suchThat(companion => companion.is(Module) && companion.owner == sym.owner)
739739
.symbol)
740740

741+
// The companion of `js.|` defines an implicit conversions from
742+
// `A | Unit` to `js.UndefOrOps[A]`. To keep this conversion in scope
743+
// in Scala 3, where we re-interpret `js.|` as a real union, we inject
744+
// it in the scope of `Unit`.
745+
if t.isRef(defn.UnitClass) && ctx.settings.scalajs.value then
746+
companions += JSDefinitions.jsdefn.UnionOpsModuleRef
747+
741748
if sym.isClass then
742749
for p <- t.parents do companions ++= iscopeRefs(p)
743750
else

library-js/src/scala/Unit.scala

Lines changed: 0 additions & 71 deletions
This file was deleted.

library-js/src/scala/scalajs/js/internal/UnitOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package scala.scalajs.js.internal
22

33
import scala.scalajs.js
44

5-
@deprecated(message = "The implicit conversion was moved to the companion object of `scala.Unit` in Scala.js", since = "3.8.0")
5+
/** Under -scalajs, this object is part of the implicit scope of `scala.Unit` */
66
object UnitOps:
77
implicit def unitOrOps[A](x: A | Unit): js.UndefOrOps[A] =
88
new js.UndefOrOps(x)

0 commit comments

Comments
 (0)