aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Stucki <nicolas.stucki@gmail.com>2017-02-01 10:04:19 +0100
committerGitHub <noreply@github.com>2017-02-01 10:04:19 +0100
commitb5185f1b4481ef61243741c7f7ed0ba8f696776b (patch)
tree7f7c18662e3e011374d1f2bbe78893e8ffac2722
parentaf7fdb32df34b352bf39f01a26653b169e0d55cf (diff)
parentf7278e16ffa8ff242b7d985803015170dbf80ce7 (diff)
downloaddotty-b5185f1b4481ef61243741c7f7ed0ba8f696776b.tar.gz
dotty-b5185f1b4481ef61243741c7f7ed0ba8f696776b.tar.bz2
dotty-b5185f1b4481ef61243741c7f7ed0ba8f696776b.zip
Merge pull request #1919 from dotty-staging/fix-#1915
Fix #1915 Synthetic function traits need NoInits flag
-rw-r--r--compiler/src/dotty/tools/dotc/core/Definitions.scala14
-rw-r--r--compiler/src/dotty/tools/dotc/core/Phases.scala3
-rw-r--r--compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala2
-rw-r--r--compiler/src/dotty/tools/dotc/transform/Mixin.scala2
-rw-r--r--tests/run/i1915.scala9
5 files changed, 24 insertions, 6 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala
index 716c9ef23..7fe6505ff 100644
--- a/compiler/src/dotty/tools/dotc/core/Definitions.scala
+++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala
@@ -133,7 +133,7 @@ class Definitions {
ClassInfo(ScalaPackageClass.thisType, cls, ObjectType :: parentTraits, decls)
}
}
- newClassSymbol(ScalaPackageClass, name, Trait, completer)
+ newClassSymbol(ScalaPackageClass, name, Trait | NoInits, completer)
}
private def newMethod(cls: ClassSymbol, name: TermName, info: Type, flags: FlagSet = EmptyFlags): TermSymbol =
@@ -770,6 +770,18 @@ class Definitions {
lazy val PhantomClasses = Set[Symbol](AnyClass, AnyValClass, NullClass, NothingClass)
+ /** Classes that are known not to have an initializer irrespective of
+ * whether NoInits is set. Note: FunctionXXLClass is in this set
+ * because if it is compiled by Scala2, it does not get a NoInit flag.
+ * But since it is introduced only at erasure, there's no chance
+ * for augmentScala2Traits to do anything on a class that inherits it. So
+ * it also misses an implementation class, which means that the usual scheme
+ * of calling a superclass init in the implementation class of a Scala2
+ * trait gets screwed up. Therefore, it is mandatory that FunctionXXL
+ * is treated as a NoInit trait.
+ */
+ lazy val NoInitClasses = PhantomClasses + FunctionXXLClass
+
def isPolymorphicAfterErasure(sym: Symbol) =
(sym eq Any_isInstanceOf) || (sym eq Any_asInstanceOf)
diff --git a/compiler/src/dotty/tools/dotc/core/Phases.scala b/compiler/src/dotty/tools/dotc/core/Phases.scala
index 6a53e1b30..d217afed8 100644
--- a/compiler/src/dotty/tools/dotc/core/Phases.scala
+++ b/compiler/src/dotty/tools/dotc/core/Phases.scala
@@ -40,9 +40,6 @@ trait Phases {
def atPhaseNotLaterThan[T](limit: Phase)(op: Context => T): T =
if (!limit.exists || phase <= limit) op(this) else atPhase(limit)(op)
- def atPhaseNotLaterThanTyper[T](op: Context => T): T =
- atPhaseNotLaterThan(base.typerPhase)(op)
-
def isAfterTyper: Boolean = base.isAfterTyper(phase)
}
diff --git a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala
index 97a82e80d..5b751ef3c 100644
--- a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala
+++ b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala
@@ -818,7 +818,7 @@ class ClassfileParser(
case Some(entry) =>
val outerName = entry.outerName.stripModuleClassSuffix
val owner = classSymbol(outerName)
- val result = ctx.atPhaseNotLaterThanTyper { implicit ctx =>
+ val result = ctx.atPhaseNotLaterThan(ctx.typerPhase) { implicit ctx =>
getMember(owner, innerName.toTypeName)
}
assert(result ne NoSymbol,
diff --git a/compiler/src/dotty/tools/dotc/transform/Mixin.scala b/compiler/src/dotty/tools/dotc/transform/Mixin.scala
index 27cfc835a..fd4370d3e 100644
--- a/compiler/src/dotty/tools/dotc/transform/Mixin.scala
+++ b/compiler/src/dotty/tools/dotc/transform/Mixin.scala
@@ -175,7 +175,7 @@ class Mixin extends MiniPhaseTransform with SymTransformer { thisTransform =>
case Some(call) =>
if (defn.PhantomClasses.contains(baseCls)) Nil else call :: Nil
case None =>
- if (baseCls.is(NoInitsTrait) || defn.PhantomClasses.contains(baseCls)) Nil
+ if (baseCls.is(NoInitsTrait) || defn.NoInitClasses.contains(baseCls)) Nil
else {
//println(i"synth super call ${baseCls.primaryConstructor}: ${baseCls.primaryConstructor.info}")
transformFollowingDeep(superRef(baseCls.primaryConstructor).appliedToNone) :: Nil
diff --git a/tests/run/i1915.scala b/tests/run/i1915.scala
new file mode 100644
index 000000000..ee192f6fe
--- /dev/null
+++ b/tests/run/i1915.scala
@@ -0,0 +1,9 @@
+object Test {
+ def main(args: Array[String]) = {
+ assert(new IntFunction26().apply(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26) == 42)
+ }
+}
+
+class IntFunction26 extends Function26[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int] {
+ def apply(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int, x22: Int, x23: Int, x24: Int, x25: Int, x26: Int) = 42
+}