Skip to content

Commit b5185f1

Browse files
Merge pull request #1919 from dotty-staging/fix-#1915
Fix #1915 Synthetic function traits need NoInits flag
2 parents af7fdb3 + f7278e1 commit b5185f1

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class Definitions {
133133
ClassInfo(ScalaPackageClass.thisType, cls, ObjectType :: parentTraits, decls)
134134
}
135135
}
136-
newClassSymbol(ScalaPackageClass, name, Trait, completer)
136+
newClassSymbol(ScalaPackageClass, name, Trait | NoInits, completer)
137137
}
138138

139139
private def newMethod(cls: ClassSymbol, name: TermName, info: Type, flags: FlagSet = EmptyFlags): TermSymbol =
@@ -770,6 +770,18 @@ class Definitions {
770770

771771
lazy val PhantomClasses = Set[Symbol](AnyClass, AnyValClass, NullClass, NothingClass)
772772

773+
/** Classes that are known not to have an initializer irrespective of
774+
* whether NoInits is set. Note: FunctionXXLClass is in this set
775+
* because if it is compiled by Scala2, it does not get a NoInit flag.
776+
* But since it is introduced only at erasure, there's no chance
777+
* for augmentScala2Traits to do anything on a class that inherits it. So
778+
* it also misses an implementation class, which means that the usual scheme
779+
* of calling a superclass init in the implementation class of a Scala2
780+
* trait gets screwed up. Therefore, it is mandatory that FunctionXXL
781+
* is treated as a NoInit trait.
782+
*/
783+
lazy val NoInitClasses = PhantomClasses + FunctionXXLClass
784+
773785
def isPolymorphicAfterErasure(sym: Symbol) =
774786
(sym eq Any_isInstanceOf) || (sym eq Any_asInstanceOf)
775787

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ trait Phases {
4040
def atPhaseNotLaterThan[T](limit: Phase)(op: Context => T): T =
4141
if (!limit.exists || phase <= limit) op(this) else atPhase(limit)(op)
4242

43-
def atPhaseNotLaterThanTyper[T](op: Context => T): T =
44-
atPhaseNotLaterThan(base.typerPhase)(op)
45-
4643
def isAfterTyper: Boolean = base.isAfterTyper(phase)
4744
}
4845

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ class ClassfileParser(
818818
case Some(entry) =>
819819
val outerName = entry.outerName.stripModuleClassSuffix
820820
val owner = classSymbol(outerName)
821-
val result = ctx.atPhaseNotLaterThanTyper { implicit ctx =>
821+
val result = ctx.atPhaseNotLaterThan(ctx.typerPhase) { implicit ctx =>
822822
getMember(owner, innerName.toTypeName)
823823
}
824824
assert(result ne NoSymbol,

compiler/src/dotty/tools/dotc/transform/Mixin.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class Mixin extends MiniPhaseTransform with SymTransformer { thisTransform =>
175175
case Some(call) =>
176176
if (defn.PhantomClasses.contains(baseCls)) Nil else call :: Nil
177177
case None =>
178-
if (baseCls.is(NoInitsTrait) || defn.PhantomClasses.contains(baseCls)) Nil
178+
if (baseCls.is(NoInitsTrait) || defn.NoInitClasses.contains(baseCls)) Nil
179179
else {
180180
//println(i"synth super call ${baseCls.primaryConstructor}: ${baseCls.primaryConstructor.info}")
181181
transformFollowingDeep(superRef(baseCls.primaryConstructor).appliedToNone) :: Nil

tests/run/i1915.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object Test {
2+
def main(args: Array[String]) = {
3+
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)
4+
}
5+
}
6+
7+
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] {
8+
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
9+
}

0 commit comments

Comments
 (0)