Skip to content

Commit 6070cce

Browse files
authored
Merge pull request #1617 from dotty-staging/change-shadow-scala
Introduce scalaShadowing package
2 parents 3e76f3c + 69c9300 commit 6070cce

File tree

12 files changed

+233
-32
lines changed

12 files changed

+233
-32
lines changed

src/dotty/Pair.scala

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

src/dotty/Singleton.scala

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

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

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ class Definitions {
140140
lazy val Sys_errorR = SysPackage.moduleClass.requiredMethodRef(nme.error)
141141
def Sys_error(implicit ctx: Context) = Sys_errorR.symbol
142142

143+
/** The `scalaShadowing` package is used to safely modify classes and
144+
* objects in scala so that they can be used from dotty. They will
145+
* be visible as members of the `scala` package, replacing any objects
146+
* or classes with the same name. But their binary artifacts are
147+
* in `scalaShadowing` so they don't clash with the same-named `scala`
148+
* members at runtime.
149+
*/
150+
lazy val ScalaShadowingPackageVal = ctx.requiredPackage("scalaShadowing")
151+
lazy val ScalaShadowingPackageClass = ScalaShadowingPackageVal.moduleClass.asClass
152+
143153
/** Note: We cannot have same named methods defined in Object and Any (and AnyVal, for that matter)
144154
* because after erasure the Any and AnyVal references get remapped to the Object methods
145155
* which would result in a double binding assertion failure.
@@ -410,8 +420,6 @@ class Definitions {
410420
lazy val StringAdd_plusR = StringAddClass.requiredMethodRef(nme.raw.PLUS)
411421
def StringAdd_+(implicit ctx: Context) = StringAdd_plusR.symbol
412422

413-
lazy val PairType: TypeRef = ctx.requiredClassRef("dotty.Pair")
414-
def PairClass(implicit ctx: Context) = PairType.symbol.asClass
415423
lazy val PartialFunctionType: TypeRef = ctx.requiredClassRef("scala.PartialFunction")
416424
def PartialFunctionClass(implicit ctx: Context) = PartialFunctionType.symbol.asClass
417425
lazy val AbstractPartialFunctionType: TypeRef = ctx.requiredClassRef("scala.runtime.AbstractPartialFunction")
@@ -450,37 +458,37 @@ class Definitions {
450458
def StaticAnnotationClass(implicit ctx: Context) = StaticAnnotationType.symbol.asClass
451459

452460
// Annotation classes
453-
lazy val AliasAnnotType = ctx.requiredClassRef("dotty.annotation.internal.Alias")
461+
lazy val AliasAnnotType = ctx.requiredClassRef("scala.annotation.internal.Alias")
454462
def AliasAnnot(implicit ctx: Context) = AliasAnnotType.symbol.asClass
455-
lazy val AnnotationDefaultAnnotType = ctx.requiredClassRef("dotty.annotation.internal.AnnotationDefault")
463+
lazy val AnnotationDefaultAnnotType = ctx.requiredClassRef("scala.annotation.internal.AnnotationDefault")
456464
def AnnotationDefaultAnnot(implicit ctx: Context) = AnnotationDefaultAnnotType.symbol.asClass
457-
lazy val BodyAnnotType = ctx.requiredClassRef("dotty.annotation.internal.Body")
465+
lazy val BodyAnnotType = ctx.requiredClassRef("scala.annotation.internal.Body")
458466
def BodyAnnot(implicit ctx: Context) = BodyAnnotType.symbol.asClass
459-
lazy val ChildAnnotType = ctx.requiredClassRef("dotty.annotation.internal.Child")
467+
lazy val ChildAnnotType = ctx.requiredClassRef("scala.annotation.internal.Child")
460468
def ChildAnnot(implicit ctx: Context) = ChildAnnotType.symbol.asClass
461-
lazy val CovariantBetweenAnnotType = ctx.requiredClassRef("dotty.annotation.internal.CovariantBetween")
469+
lazy val CovariantBetweenAnnotType = ctx.requiredClassRef("scala.annotation.internal.CovariantBetween")
462470
def CovariantBetweenAnnot(implicit ctx: Context) = CovariantBetweenAnnotType.symbol.asClass
463-
lazy val ContravariantBetweenAnnotType = ctx.requiredClassRef("dotty.annotation.internal.ContravariantBetween")
471+
lazy val ContravariantBetweenAnnotType = ctx.requiredClassRef("scala.annotation.internal.ContravariantBetween")
464472
def ContravariantBetweenAnnot(implicit ctx: Context) = ContravariantBetweenAnnotType.symbol.asClass
465473
lazy val DeprecatedAnnotType = ctx.requiredClassRef("scala.deprecated")
466474
def DeprecatedAnnot(implicit ctx: Context) = DeprecatedAnnotType.symbol.asClass
467475
lazy val ImplicitNotFoundAnnotType = ctx.requiredClassRef("scala.annotation.implicitNotFound")
468476
def ImplicitNotFoundAnnot(implicit ctx: Context) = ImplicitNotFoundAnnotType.symbol.asClass
469477
lazy val InlineAnnotType = ctx.requiredClassRef("scala.inline")
470478
def InlineAnnot(implicit ctx: Context) = InlineAnnotType.symbol.asClass
471-
lazy val InlineParamAnnotType = ctx.requiredClassRef("dotty.annotation.internal.InlineParam")
479+
lazy val InlineParamAnnotType = ctx.requiredClassRef("scala.annotation.internal.InlineParam")
472480
def InlineParamAnnot(implicit ctx: Context) = InlineParamAnnotType.symbol.asClass
473-
lazy val InvariantBetweenAnnotType = ctx.requiredClassRef("dotty.annotation.internal.InvariantBetween")
481+
lazy val InvariantBetweenAnnotType = ctx.requiredClassRef("scala.annotation.internal.InvariantBetween")
474482
def InvariantBetweenAnnot(implicit ctx: Context) = InvariantBetweenAnnotType.symbol.asClass
475483
lazy val MigrationAnnotType = ctx.requiredClassRef("scala.annotation.migration")
476484
def MigrationAnnot(implicit ctx: Context) = MigrationAnnotType.symbol.asClass
477485
lazy val NativeAnnotType = ctx.requiredClassRef("scala.native")
478486
def NativeAnnot(implicit ctx: Context) = NativeAnnotType.symbol.asClass
479487
lazy val RemoteAnnotType = ctx.requiredClassRef("scala.remote")
480488
def RemoteAnnot(implicit ctx: Context) = RemoteAnnotType.symbol.asClass
481-
lazy val RepeatedAnnotType = ctx.requiredClassRef("dotty.annotation.internal.Repeated")
489+
lazy val RepeatedAnnotType = ctx.requiredClassRef("scala.annotation.internal.Repeated")
482490
def RepeatedAnnot(implicit ctx: Context) = RepeatedAnnotType.symbol.asClass
483-
lazy val SourceFileAnnotType = ctx.requiredClassRef("dotty.annotation.internal.SourceFile")
491+
lazy val SourceFileAnnotType = ctx.requiredClassRef("scala.annotation.internal.SourceFile")
484492
def SourceFileAnnot(implicit ctx: Context) = SourceFileAnnotType.symbol.asClass
485493
lazy val ScalaSignatureAnnotType = ctx.requiredClassRef("scala.reflect.ScalaSignature")
486494
def ScalaSignatureAnnot(implicit ctx: Context) = ScalaSignatureAnnotType.symbol.asClass
@@ -510,7 +518,7 @@ class Definitions {
510518
def UncheckedStableAnnot(implicit ctx: Context) = UncheckedStableAnnotType.symbol.asClass
511519
lazy val UncheckedVarianceAnnotType = ctx.requiredClassRef("scala.annotation.unchecked.uncheckedVariance")
512520
def UncheckedVarianceAnnot(implicit ctx: Context) = UncheckedVarianceAnnotType.symbol.asClass
513-
lazy val UnsafeNonvariantAnnotType = ctx.requiredClassRef("dotty.annotation.internal.UnsafeNonvariant")
521+
lazy val UnsafeNonvariantAnnotType = ctx.requiredClassRef("scala.annotation.internal.UnsafeNonvariant")
514522
def UnsafeNonvariantAnnot(implicit ctx: Context) = UnsafeNonvariantAnnotType.symbol.asClass
515523
lazy val VolatileAnnotType = ctx.requiredClassRef("scala.volatile")
516524
def VolatileAnnot(implicit ctx: Context) = VolatileAnnotType.symbol.asClass
@@ -781,6 +789,11 @@ class Definitions {
781789
if (!_isInitialized) {
782790
// force initialization of every symbol that is synthesized or hijacked by the compiler
783791
val forced = syntheticCoreClasses ++ syntheticCoreMethods ++ ScalaValueClasses()
792+
793+
// Enter all symbols from the scalaShadowing package in the scala package
794+
for (m <- ScalaShadowingPackageClass.info.decls)
795+
ScalaPackageClass.enter(m)
796+
784797
_isInitialized = true
785798
}
786799
}

src/dotty/annotation/internal/Alias.scala renamed to src/scala/annotation/internal/Alias.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package dotty.annotation.internal
1+
package scala.annotation.internal
22

33
import scala.annotation.Annotation
44

src/dotty/annotation/internal/AnnotationDefault.scala renamed to src/scala/annotation/internal/AnnotationDefault.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package dotty.annotation.internal
1+
package scala.annotation.internal
22

33
import scala.annotation.Annotation
44

src/dotty/annotation/internal/Body.scala renamed to src/scala/annotation/internal/Body.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package dotty.annotation.internal
1+
package scala.annotation.internal
22

33
import scala.annotation.Annotation
44

src/dotty/annotation/internal/Child.scala renamed to src/scala/annotation/internal/Child.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package dotty.annotation.internal
1+
package scala.annotation.internal
22

33
import scala.annotation.Annotation
44

@@ -9,7 +9,7 @@ import scala.annotation.Annotation
99
* case class B() extends A
1010
* case class C() extends A
1111
*
12-
* Then the class symbol `A` would carry the annotations
12+
* Then the class symbol `A` would carry the annotations
1313
* `@Child[Bref] @Child[Cref]` where `Bref`, `Cref` are TypeRefs
1414
* referring to the class symbols of `B` and `C`
1515
*/

src/dotty/annotation/internal/InlineParam.scala renamed to src/scala/annotation/internal/InlineParam.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package dotty.annotation.internal
1+
package scala.annotation.internal
22

33
import scala.annotation.Annotation
44

src/dotty/annotation/internal/Repeated.scala renamed to src/scala/annotation/internal/Repeated.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package dotty.annotation.internal
1+
package scala.annotation.internal
22

33
import scala.annotation.Annotation
44

src/dotty/annotation/internal/SourceFile.scala renamed to src/scala/annotation/internal/SourceFile.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package dotty.annotation.internal
1+
package scala.annotation.internal
22

33
import scala.annotation.Annotation
44

0 commit comments

Comments
 (0)