Skip to content

Commit fbbc51f

Browse files
Backport "Revert "do not patch the implicit scope of scala.Unit in Scala.js"" to 3.8.0 (#24529)
Backports #24475 to the 3.8.0-RC2. PR submitted by the release tooling. [skip ci]
2 parents b1f42ca + b156cbc commit fbbc51f

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
@@ -733,6 +733,13 @@ trait ImplicitRunInfo:
733733
.suchThat(companion => companion.is(Module) && companion.owner == sym.owner)
734734
.symbol)
735735

736+
// The companion of `js.|` defines an implicit conversions from
737+
// `A | Unit` to `js.UndefOrOps[A]`. To keep this conversion in scope
738+
// in Scala 3, where we re-interpret `js.|` as a real union, we inject
739+
// it in the scope of `Unit`.
740+
if t.isRef(defn.UnitClass) && ctx.settings.scalajs.value then
741+
companions += JSDefinitions.jsdefn.UnionOpsModuleRef
742+
736743
if sym.isClass then
737744
for p <- t.parents do companions ++= iscopeRefs(p)
738745
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)