Skip to content

Commit 15a9450

Browse files
committed
wip: undefOr2ops implicit conversion, more complete erasure
1 parent e21623f commit 15a9450

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ final class JSDefinitions()(using Context) {
5858
def PseudoUnion_from(using Context) = PseudoUnion_fromR.symbol
5959
@threadUnsafe lazy val PseudoUnion_fromTypeConstructorR = PseudoUnionModule.requiredMethodRef("fromTypeConstructor")
6060
def PseudoUnion_fromTypeConstructor(using Context) = PseudoUnion_fromTypeConstructorR.symbol
61+
@threadUnsafe lazy val PseudoUnion_undefOr2opsR = PseudoUnionModule.requiredMethodRef("undefOr2ops")
6162

6263
@threadUnsafe lazy val JSArrayType: TypeRef = requiredClassRef("scala.scalajs.js.Array")
6364
def JSArrayClass(using Context) = JSArrayType.symbol.asClass

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import collection.mutable
1111
import Denotations.SingleDenotation
1212
import util.{SimpleIdentityMap, SourceFile, NoSource}
1313
import typer.ImportInfo.RootRef
14+
import backend.sjs.JSDefinitions
1415

1516
import scala.annotation.tailrec
1617

@@ -1344,14 +1345,24 @@ class Definitions {
13441345
private val PredefImportFns: RootRef =
13451346
RootRef(() => ScalaPredefModule.termRef, isPredef=true)
13461347

1348+
@tu private lazy val ScalaJsRootImportFn: RootRef =
1349+
RootRef(() => JSDefinitions.jsdefn.PseudoUnionModuleRef)
1350+
// TODO: Doesn't work because of the way ImportInfo#rootImport works currently
1351+
// RootRef(() => JSDefinitions.jsdefn.PseudoUnion_undefOr2ops)
1352+
13471353
@tu private lazy val JavaRootImportFns: List[RootRef] =
13481354
if ctx.settings.YnoImports.value then Nil
13491355
else JavaImportFns
13501356

13511357
@tu private lazy val ScalaRootImportFns: List[RootRef] =
1352-
if ctx.settings.YnoImports.value then Nil
1353-
else if ctx.settings.YnoPredef.value then ScalaImportFns
1354-
else ScalaImportFns :+ PredefImportFns
1358+
if ctx.settings.YnoImports.value then
1359+
Nil
1360+
else if ctx.settings.YnoPredef.value then
1361+
ScalaImportFns
1362+
else if !ctx.settings.scalajs.value then
1363+
ScalaImportFns :+ PredefImportFns
1364+
else
1365+
ScalaImportFns :+ PredefImportFns :+ ScalaJsRootImportFn
13551366

13561367
@tu private lazy val JavaRootImportTypes: List[TermRef] = JavaRootImportFns.map(_.refFn())
13571368
@tu private lazy val ScalaRootImportTypes: List[TermRef] = ScalaRootImportFns.map(_.refFn())

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,10 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
593593
val tp1 =
594594
if sourceLanguage.isScala2 && ctx.settings.scalajs.value then
595595
val eraseAsPseudoUnion = new TypeMap:
596-
def apply(tp: Type) = tp match
596+
// TODO: This isn't good enough since an OrType might be
597+
// hidden behind a bound for example; we might have no
598+
// choice but to move this logic to the TypeErasure class.
599+
def apply(tp: Type) = tp.dealias match
597600
case tp: OrType =>
598601
JSDefinitions.jsdefn.PseudoUnionType
599602
case tp =>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import Decorators._
1818
object ImportInfo {
1919

2020
case class RootRef(refFn: () => TermRef, isPredef: Boolean = false)
21+
// TODO: Replace by one of those:
22+
// case class RootRef(refFn: () => TermRef, selector: Option[untpd.ImportSelector])
23+
// case class RootRef(refFn: () => TermRef, selector: Tree = EmptyTree)
2124

2225
/** The import info for a root import */
2326
def rootImport(ref: RootRef)(using Context): ImportInfo =

0 commit comments

Comments
 (0)