Skip to content

Commit f858b84

Browse files
committed
Fix compiling with the 2.13 collections
- Always rely on -Ynew-collections to change our behavior, attempting to automatically detect which version we're on leads to cycles. - In the new collections, the scala.Serializable class has been replaced by a type alias of java.io.Serializable - The `<:<` class was moved from the Predef object to the scala package.
1 parent eeb314f commit f858b84

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,16 +347,19 @@ class Definitions {
347347

348348
lazy val ScalaPredefModuleRef: TermRef = ctx.requiredModuleRef("scala.Predef")
349349
def ScalaPredefModule(implicit ctx: Context): Symbol = ScalaPredefModuleRef.symbol
350-
351-
lazy val Predef_ConformsR: TypeRef = ScalaPredefModule.requiredClass("<:<").typeRef
352-
def Predef_Conforms(implicit ctx: Context): Symbol = Predef_ConformsR.symbol
353350
lazy val Predef_conformsR: TermRef = ScalaPredefModule.requiredMethodRef(nme.conforms_)
354351
def Predef_conforms(implicit ctx: Context): Symbol = Predef_conformsR.symbol
355352
lazy val Predef_classOfR: TermRef = ScalaPredefModule.requiredMethodRef(nme.classOf)
356353
def Predef_classOf(implicit ctx: Context): Symbol = Predef_classOfR.symbol
357354
lazy val Predef_undefinedR: TermRef = ScalaPredefModule.requiredMethodRef(nme.???)
358355
def Predef_undefined(implicit ctx: Context): Symbol = Predef_undefinedR.symbol
359356

357+
def SubTypeClass(implicit ctx: Context): Symbol =
358+
if (isNewCollections)
359+
ctx.requiredClass("scala.<:<")
360+
else
361+
ScalaPredefModule.requiredClass("<:<")
362+
360363
lazy val ScalaRuntimeModuleRef: TermRef = ctx.requiredModuleRef("scala.runtime.ScalaRunTime")
361364
def ScalaRuntimeModule(implicit ctx: Context): Symbol = ScalaRuntimeModuleRef.symbol
362365
def ScalaRuntimeClass(implicit ctx: Context): ClassSymbol = ScalaRuntimeModule.moduleClass.asClass
@@ -397,8 +400,7 @@ class Definitions {
397400
def newArrayMethod(implicit ctx: Context): TermSymbol = DottyArraysModule.requiredMethod("newArray")
398401

399402
// TODO: Remove once we drop support for 2.12 standard library
400-
lazy val isNewCollections: Boolean = ctx.settings.YnewCollections.value ||
401-
ctx.base.staticRef("scala.collection.IterableOnce".toTypeName).exists
403+
lazy val isNewCollections: Boolean = ctx.settings.YnewCollections.value
402404

403405
def getWrapVarargsArrayModule: Symbol = if (isNewCollections) ScalaRuntimeModule else ScalaPredefModule
404406

@@ -585,7 +587,11 @@ class Definitions {
585587

586588
lazy val ThrowableType: TypeRef = ctx.requiredClassRef("java.lang.Throwable")
587589
def ThrowableClass(implicit ctx: Context): ClassSymbol = ThrowableType.symbol.asClass
588-
lazy val SerializableType: TypeRef = ctx.requiredClassRef("scala.Serializable")
590+
lazy val SerializableType: TypeRef =
591+
if (isNewCollections)
592+
JavaSerializableClass.typeRef
593+
else
594+
ctx.requiredClassRef("scala.Serializable")
589595
def SerializableClass(implicit ctx: Context): ClassSymbol = SerializableType.symbol.asClass
590596
lazy val StringBuilderType: TypeRef = ctx.requiredClassRef("scala.collection.mutable.StringBuilder")
591597
def StringBuilderClass(implicit ctx: Context): ClassSymbol = StringBuilderType.symbol.asClass

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ object Implicits {
140140
ctx.scala2Mode && tpw.derivesFrom(defn.FunctionClass(1)) && ref.symbol != defn.Predef_conforms
141141
val isImplicitConverter = tpw.derivesFrom(defn.Predef_ImplicitConverter)
142142
val isConforms = // An implementation of <:< counts as a view, except that $conforms is always omitted
143-
tpw.derivesFrom(defn.Predef_Conforms) && ref.symbol != defn.Predef_conforms
143+
tpw.derivesFrom(defn.SubTypeClass) &&
144+
(defn.isNewCollections || // In 2.13, the type of `$conforms` changed from `A <:< A` to `A => A`
145+
ref.symbol != defn.Predef_conforms)
144146
val hasExtensions = resType match {
145147
case SelectionProto(name, _, _, _) =>
146148
tpw.memberBasedOnFlags(name, required = ExtensionMethod).exists

0 commit comments

Comments
 (0)