From d0621108bad55f9fc66c1c5ade9a0b7edb3117e7 Mon Sep 17 00:00:00 2001 From: Abel Nieto Date: Thu, 16 Mar 2017 15:49:06 -0400 Subject: Move 'invalid super qualifier' error to new error format. As part of https://github.com/lampepfl/dotty/issues/1589, use the new error message for static super references where the qualifier isn't a parent of the class. Tested: Added unit test. --- .../tools/dotc/reporting/diagnostic/ErrorMessageID.java | 1 + .../tools/dotc/reporting/diagnostic/messages.scala | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) (limited to 'compiler/src/dotty/tools/dotc/reporting') 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 + } } -- cgit v1.2.3