diff options
Diffstat (limited to 'compiler/src/dotty/tools')
7 files changed, 33 insertions, 8 deletions
diff --git a/compiler/src/dotty/tools/dotc/Compiler.scala b/compiler/src/dotty/tools/dotc/Compiler.scala index f413fc902..efde897cd 100644 --- a/compiler/src/dotty/tools/dotc/Compiler.scala +++ b/compiler/src/dotty/tools/dotc/Compiler.scala @@ -92,12 +92,12 @@ class Compiler { new ElimStaticThis, // Replace `this` references to static objects by global identifiers new Flatten, // Lift all inner classes to package scope new RestoreScopes), // Repair scopes rendered invalid by moving definitions in prior phases of the group - List(new ExpandPrivate, // Widen private definitions accessed from nested classes + List(new MoveStatics, // Move static methods to companion classes + new ExpandPrivate, // Widen private definitions accessed from nested classes new SelectStatic, // get rid of selects that would be compiled into GetStatic new CollectEntryPoints, // Find classes with main methods new CollectSuperCalls, // Find classes that are called with super new DropInlined, // Drop Inlined nodes, since backend has no use for them - new MoveStatics, // Move static methods to companion classes new LabelDefs), // Converts calls to labels to jumps List(new GenBCode) // Generate JVM bytecode ) diff --git a/compiler/src/dotty/tools/dotc/core/Periods.scala b/compiler/src/dotty/tools/dotc/core/Periods.scala index 29d9d208f..892a1f59a 100644 --- a/compiler/src/dotty/tools/dotc/core/Periods.scala +++ b/compiler/src/dotty/tools/dotc/core/Periods.scala @@ -46,9 +46,9 @@ object Periods { * It is coded as follows: * * sign, always 0 1 bit - * runid 19 bits - * last phase id: 6 bits - * #phases before last: 6 bits + * runid 17 bits + * last phase id: 7 bits + * #phases before last: 7 bits * * // Dmitry: sign == 0 isn't actually always true, in some cases phaseId == -1 is used for shifts, that easily creates code < 0 */ @@ -108,6 +108,7 @@ object Periods { else Nowhere + /** The smallest period containing two periods */ def | (that: Period): Period = Period(this.runId, this.firstPhaseId min that.firstPhaseId, diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java index 7b56c8ed4..6ea168b99 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java @@ -55,6 +55,7 @@ public enum ErrorMessageID { RecursiveValueNeedsResultTypeID, CyclicReferenceInvolvingID, CyclicReferenceInvolvingImplicitID, + SuperQualMustBeParentID, ; public int errorNumber() { diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 4c53fa496..6fa056646 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -1192,4 +1192,21 @@ object messages { |""".stripMargin } + case class SuperQualMustBeParent(qual: untpd.Ident, cls: Symbols.ClassSymbol)(implicit ctx: Context) + extends Message(SuperQualMustBeParentID) { + + val msg = hl"""|$qual does not name a parent of $cls""" + + val kind = "Reference" + + private val parents: Seq[String] = (cls.info.parents map (_.name.show)).sorted + + val explanation = + hl"""|When a qualifier ${"T"} is used in a ${"super"} prefix of the form ${"C.super[T]"}, + |${"T"} must be a parent type of ${"C"}. + | + |In this case, the parents of $cls are: + |${parents.mkString(" - ", "\n - ", "")} + |""".stripMargin + } } diff --git a/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala b/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala index 83cd395ff..8f99ef1d0 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala @@ -3,7 +3,7 @@ package transform import core._ import dotty.tools.dotc.ast.tpd -import dotty.tools.dotc.core.DenotTransformers.{SymTransformer, IdentityDenotTransformer} +import dotty.tools.dotc.core.DenotTransformers.{IdentityDenotTransformer, SymTransformer} import Contexts.Context import Symbols._ import Scopes._ @@ -11,13 +11,16 @@ import Flags._ import StdNames._ import SymDenotations._ import Types._ + import collection.mutable import TreeTransforms._ import Decorators._ import ast.Trees._ import TreeTransforms._ import java.io.File.separatorChar + import ValueClasses._ +import dotty.tools.dotc.core.Phases.Phase /** Make private term members that are accessed from another class * non-private by resetting the Private flag and expanding their name. @@ -38,6 +41,9 @@ class ExpandPrivate extends MiniPhaseTransform with IdentityDenotTransformer { t override def phaseName: String = "expandPrivate" + // This phase moves methods around (in infotransform) so it may need to make other methods public + override def runsAfter: Set[Class[_ <: Phase]] = Set(classOf[MoveStatics]) + override def checkPostCondition(tree: Tree)(implicit ctx: Context): Unit = { tree match { case t: DefDef => diff --git a/compiler/src/dotty/tools/dotc/transform/MoveStatics.scala b/compiler/src/dotty/tools/dotc/transform/MoveStatics.scala index 5c2cd3145..b0ee0930d 100644 --- a/compiler/src/dotty/tools/dotc/transform/MoveStatics.scala +++ b/compiler/src/dotty/tools/dotc/transform/MoveStatics.scala @@ -9,6 +9,7 @@ import dotty.tools.dotc.core.Decorators._ import dotty.tools.dotc.core.NameOps._ import dotty.tools.dotc.core.{Flags, Names} import dotty.tools.dotc.core.Names.Name +import dotty.tools.dotc.core.Phases.Phase import dotty.tools.dotc.core.Symbols._ import dotty.tools.dotc.core.Types.MethodType import dotty.tools.dotc.transform.TreeTransforms.{MiniPhaseTransform, TransformerInfo} @@ -19,7 +20,6 @@ class MoveStatics extends MiniPhaseTransform with SymTransformer { thisTransform import tpd._ override def phaseName = "moveStatic" - def transformSym(sym: SymDenotation)(implicit ctx: Context): SymDenotation = { if (sym.hasAnnotation(defn.ScalaStaticAnnot) && sym.owner.is(Flags.Module) && sym.owner.companionClass.exists) { sym.owner.asClass.delete(sym.symbol) diff --git a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala index 6e774e38e..3d20583f4 100644 --- a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -298,7 +298,7 @@ trait TypeAssigner { case p :: Nil => p case Nil => - errorType(em"$mix does not name a parent class of $cls", tree.pos) + errorType(SuperQualMustBeParent(mix, cls), tree.pos) case p :: q :: _ => errorType("ambiguous parent class qualifier", tree.pos) } |