diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2017-02-22 21:10:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-22 21:10:47 +0100 |
commit | 43612f97cca568e0d48f44aad80d203d452d258e (patch) | |
tree | f9028c14e9fa76e608eeff223a936ef7af191059 /compiler/src/dotty/tools/dotc | |
parent | a0c2e55b23107d473b3e99aad9f515e23f321822 (diff) | |
parent | 3c2b09f2a16d04b7f5c10c87faba14c62e5896a4 (diff) | |
download | dotty-43612f97cca568e0d48f44aad80d203d452d258e.tar.gz dotty-43612f97cca568e0d48f44aad80d203d452d258e.tar.bz2 dotty-43612f97cca568e0d48f44aad80d203d452d258e.zip |
Merge pull request #2012 from ennru/ennru_CantInstantiateAbstract
Change 'is abstract; cannot be instantiated' to Message
Diffstat (limited to 'compiler/src/dotty/tools/dotc')
3 files changed, 24 insertions, 2 deletions
diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java index c74130b44..2bf15cb7c 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java @@ -49,7 +49,9 @@ public enum ErrorMessageID { OverridesNothingButNameExistsID, ForwardReferenceExtendsOverDefinitionID, ExpectedTokenButFoundID, - MixedLeftAndRightAssociativeOpsID; + MixedLeftAndRightAssociativeOpsID, + CantInstantiateAbstractClassOrTraitID, + ; public int errorNumber() { return ordinal() - 2; diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index e818e7a42..34190c114 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -1127,4 +1127,23 @@ object messages { |""".stripMargin } + case class CantInstantiateAbstractClassOrTrait(cls: Symbol, isTrait: Boolean)(implicit ctx: Context) + extends Message(CantInstantiateAbstractClassOrTraitID) { + val kind = "Usage" + private val traitOrAbstract = if (isTrait) hl"a trait" else hl"abstract" + val msg = hl"""${cls.name} is ${traitOrAbstract}; it cannot be instantiated""" + val explanation = + hl"""|Abstract classes and traits need to be extended by a concrete class or object + |to make their functionality accessible. + | + |You may want to create an anonymous class extending ${cls.name} with + | ${s"class ${cls.name} { }"} + | + |or add a companion object with + | ${s"object ${cls.name} extends ${cls.name}"} + | + |You need to implement any abstract members in both cases. + |""".stripMargin + } + } diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index fb0497c2b..48f9243f7 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -29,6 +29,7 @@ import ErrorReporting.{err, errorType} import config.Printers.typr import collection.mutable import SymDenotations.NoCompleter +import dotty.tools.dotc.reporting.diagnostic.messages.CantInstantiateAbstractClassOrTrait import dotty.tools.dotc.transform.ValueClasses._ object Checking { @@ -103,7 +104,7 @@ object Checking { case tref: TypeRef => val cls = tref.symbol if (cls.is(AbstractOrTrait)) - ctx.error(em"$cls is abstract; cannot be instantiated", pos) + ctx.error(CantInstantiateAbstractClassOrTrait(cls, isTrait = cls.is(Trait)), pos) if (!cls.is(Module)) { // Create a synthetic singleton type instance, and check whether // it conforms to the self type of the class as seen from that instance. |