diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index ca7a889affeb..65ad8fce38ce 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -18,6 +18,8 @@ import util.Stats import java.util.WeakHashMap import config.Config import config.Printers.{incremental, noPrinter} +import reporting.diagnostic.Message +import reporting.diagnostic.messages.BadSymbolicReference import reporting.trace trait SymDenotations { this: Context => @@ -1943,7 +1945,7 @@ object SymDenotations { /** A completer for missing references */ class StubInfo() extends LazyType { - def initializeToDefaults(denot: SymDenotation, errMsg: => String)(implicit ctx: Context) = { + def initializeToDefaults(denot: SymDenotation, errMsg: => Message)(implicit ctx: Context): Unit = { denot.info = denot match { case denot: ClassDenotation => ClassInfo(denot.owner.thisType, denot.classSymbol, Nil, EmptyScope) @@ -1955,18 +1957,9 @@ object SymDenotations { def complete(denot: SymDenotation)(implicit ctx: Context): Unit = { val sym = denot.symbol - val file = sym.associatedFile - val (location, src) = - if (file != null) (s" in $file", file.toString) - else ("", "the signature") - val name = ctx.fresh.setSetting(ctx.settings.YdebugNames, true).nameString(denot.name) - def errMsg = - i"""bad symbolic reference. A signature$location - |refers to $name in ${denot.owner.showKind} ${denot.owner.showFullName} which is not available. - |It may be completely missing from the current classpath, or the version on - |the classpath might be incompatible with the version used when compiling $src.""" - ctx.error(errMsg) - if (ctx.debug) throw new Error() + def errMsg = BadSymbolicReference(denot) + ctx.error(errMsg, sym.pos) + if (ctx.debug) throw new scala.Error() initializeToDefaults(denot, errMsg) } } diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java index b5e44eabf352..0f84c8e3bf8c 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java @@ -117,6 +117,7 @@ public enum ErrorMessageID { UnapplyInvalidNumberOfArgumentsID, StaticFieldsOnlyAllowedInObjectsID, CyclicInheritanceID, + BadSymbolicReferenceID, UnableToExtendSealedClassID, SymbolHasUnparsableVersionNumberID, SymbolChangedSemanticsInVersionID, diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 273092045c39..484ff1f2f34f 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -1968,6 +1968,26 @@ object messages { } } + case class BadSymbolicReference(denot: SymDenotation)(implicit ctx: Context) extends Message(BadSymbolicReferenceID) { + val kind = "Reference" + + val msg = { + val denotationOwner = denot.owner + val denotationName = ctx.fresh.setSetting(ctx.settings.YdebugNames, true).nameString(denot.name) + val file = denot.symbol.associatedFile + val (location, src) = + if (file != null) (s" in $file", file.toString) + else ("", "the signature") + + hl"""Bad symbolic reference. A signature$location + |refers to $denotationName in ${denotationOwner.showKind} ${denotationOwner.showFullName} which is not available. + |It may be completely missing from the current classpath, or the version on + |the classpath might be incompatible with the version used when compiling $src.""" + } + + val explanation = "" + } + case class UnableToExtendSealedClass(pclazz: Symbol)(implicit ctx: Context) extends Message(UnableToExtendSealedClassID) { val kind = "Syntax" val msg = hl"Cannot extend ${"sealed"} $pclazz in a different source file"