Skip to content

Commit e5362ad

Browse files
committed
Mark traits coming from Scala 2.12+ with flag
1 parent d64b271 commit e5362ad

File tree

6 files changed

+24
-8
lines changed

6 files changed

+24
-8
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ object Flags {
402402
/** A definition that's initialized before the super call (Scala 2.x only) */
403403
final val Scala2PreSuper = termFlag(58, "<presuper>")
404404

405+
/** A Scala 2.12 or higher trait */
406+
final val Scala_2_12_Trait = typeFlag(58, "<scala12trait>")
407+
405408
/** A macro (Scala 2.x only) */
406409
final val Macro = commonFlag(59, "<macro>")
407410

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,29 @@ object Mode {
7070
/** We are currently unpickling Scala2 info */
7171
val Scala2Unpickling = newMode(13, "Scala2Unpickling")
7272

73+
/** We are currently unpickling from Java 8 or higher */
74+
val Java8Unpickling = newMode(14, "Java8Unpickling")
75+
7376
/** Use Scala2 scheme for overloading and implicit resolution */
74-
val OldOverloadingResolution = newMode(14, "OldOverloadingResolution")
77+
val OldOverloadingResolution = newMode(15, "OldOverloadingResolution")
7578

7679
/** Allow hk applications of type lambdas to wildcard arguments;
7780
* used for checking that such applications do not normally arise
7881
*/
79-
val AllowLambdaWildcardApply = newMode(15, "AllowHKApplyToWildcards")
82+
val AllowLambdaWildcardApply = newMode(16, "AllowHKApplyToWildcards")
8083

8184
/** Read original positions when unpickling from TASTY */
82-
val ReadPositions = newMode(16, "ReadPositions")
85+
val ReadPositions = newMode(17, "ReadPositions")
8386

8487
/** Don't suppress exceptions thrown during show */
85-
val PrintShowExceptions = newMode(17, "PrintShowExceptions")
88+
val PrintShowExceptions = newMode(18, "PrintShowExceptions")
8689

8790
val PatternOrType = Pattern | Type
8891

8992
/** We are elaborating the fully qualified name of a package clause.
9093
* In this case, identifiers should never be imported.
9194
*/
92-
val InPackageClauseName = newMode(18, "InPackageClauseName")
95+
val InPackageClauseName = newMode(19, "InPackageClauseName")
9396

9497
/** We are in the IDE */
9598
val Interactive = newMode(20, "Interactive")

compiler/src/dotty/tools/dotc/core/classfile/ClassfileConstants.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ object ClassfileConstants {
1010
final val JAVA_MAJOR_VERSION = 45
1111
final val JAVA_MINOR_VERSION = 3
1212

13+
final val JAVA8_MAJOR_VERSION = 52
14+
1315
/** (see http://java.sun.com/docs/books/jvms/second_edition/jvms-clarify.html)
1416
*
1517
* If the `ACC_INTERFACE` flag is set, the `ACC_ABSTRACT` flag must also

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class ClassfileParser(
4242
protected var currentClassName: SimpleName = _ // JVM name of the current class
4343
protected var classTParams = Map[Name,Symbol]()
4444

45+
private var Scala2UnpicklingMode = Mode.Scala2Unpickling
46+
4547
classRoot.info = (new NoCompleter).withDecls(instanceScope)
4648
moduleRoot.info = (new NoCompleter).withDecls(staticScope).withSourceModule(_ => staticModule)
4749

@@ -69,6 +71,8 @@ class ClassfileParser(
6971
throw new IOException(s"class file '${in.file}' has wrong magic number 0x${toHexString(magic)}, should be 0x${toHexString(JAVA_MAGIC)}")
7072
val minorVersion = in.nextChar.toInt
7173
val majorVersion = in.nextChar.toInt
74+
if (majorVersion >= JAVA8_MAJOR_VERSION)
75+
Scala2UnpicklingMode |= Mode.Java8Unpickling
7276
if ((majorVersion < JAVA_MAJOR_VERSION) ||
7377
((majorVersion == JAVA_MAJOR_VERSION) &&
7478
(minorVersion < JAVA_MINOR_VERSION)))
@@ -714,7 +718,7 @@ class ClassfileParser(
714718

715719
def unpickleScala(bytes: Array[Byte]): Some[Embedded] = {
716720
val unpickler = new unpickleScala2.Scala2Unpickler(bytes, classRoot, moduleRoot)(ctx)
717-
unpickler.run()(ctx.addMode(Mode.Scala2Unpickling))
721+
unpickler.run()(ctx.addMode(Scala2UnpicklingMode))
718722
Some(unpickler)
719723
}
720724

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,11 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
466466
}
467467

468468
def finishSym(sym: Symbol): Symbol = {
469-
if (sym.isClass) sym.setFlag(Scala2x)
469+
if (sym.isClass) {
470+
sym.setFlag(Scala2x)
471+
if (flags.is(Trait) && ctx.mode.is(Mode.Java8Unpickling))
472+
sym.setFlag(Scala_2_12_Trait)
473+
}
470474
if (!(isRefinementClass(sym) || isUnpickleRoot(sym) || (sym is Scala2Existential))) {
471475
val owner = sym.owner
472476
if (owner.isClass)

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
362362
protected def keyString(sym: Symbol): String = {
363363
val flags = sym.flagsUNSAFE
364364
if (flags is JavaTrait) "interface"
365-
else if ((flags is Trait) && !(flags is ImplClass)) "trait"
365+
else if (flags is Trait) "trait"
366366
else if (sym.isClass) "class"
367367
else if (sym.isType) "type"
368368
else if (flags is Mutable) "var"

0 commit comments

Comments
 (0)