From bed7bea22de347cbd89adf56640fd0a6cd14dd67 Mon Sep 17 00:00:00 2001 From: Vitor Vieira Date: Thu, 30 Nov 2017 00:06:44 +0100 Subject: [PATCH 1/4] Ref #1589: Add error message for bad symbolic reference. --- .../dotty/tools/dotc/core/SymDenotations.scala | 14 ++++++-------- .../reporting/diagnostic/ErrorMessageID.java | 1 + .../dotc/reporting/diagnostic/messages.scala | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index ca7a889affeb..d543b19c2f90 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._ 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) @@ -1960,13 +1962,9 @@ object SymDenotations { 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() + val errMsg = BadSymbolicReference(location, name, denot.owner, src) + 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..59655c6ed24a 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -1968,6 +1968,24 @@ object messages { } } + case class BadSymbolicReference( + location: String, + name: String, + denotationOwner: Symbol, + src: String + )(implicit ctx: Context) extends Message(BadSymbolicReferenceID) { + val kind = "Reference" + val msg = + hl"""Bad symbolic reference. A signature$location + |refers to $name 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 = + hl"""A missing or invalid dependency was detected while loading class file '$name'. + |Check your build definition for missing or conflicting dependencies. + |Re-run with ${"-Ylog-classpath"} to obtain the information about what classpath is being applied.""" + } + 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" From f4017e1b496ce7a1de9321f9767007c6bbd75c0c Mon Sep 17 00:00:00 2001 From: Vitor Vieira Date: Fri, 1 Dec 2017 17:52:19 +0100 Subject: [PATCH 2/4] Ref #1589: Updated based on code review. --- .../dotty/tools/dotc/core/SymDenotations.scala | 9 ++------- .../dotc/reporting/diagnostic/messages.scala | 16 +++++++++------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index d543b19c2f90..65ad8fce38ce 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -19,7 +19,7 @@ import java.util.WeakHashMap import config.Config import config.Printers.{incremental, noPrinter} import reporting.diagnostic.Message -import reporting.diagnostic.messages._ +import reporting.diagnostic.messages.BadSymbolicReference import reporting.trace trait SymDenotations { this: Context => @@ -1957,12 +1957,7 @@ 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) - val errMsg = BadSymbolicReference(location, name, denot.owner, src) + 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/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 59655c6ed24a..2db877731969 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -1968,16 +1968,18 @@ object messages { } } - case class BadSymbolicReference( - location: String, - name: String, - denotationOwner: Symbol, - src: String - )(implicit ctx: Context) extends Message(BadSymbolicReferenceID) { + case class BadSymbolicReference(denot: SymDenotation)(implicit ctx: Context) extends Message(BadSymbolicReferenceID) { val kind = "Reference" + + private val file = denot.symbol.associatedFile + private val (location, src) = + if (file != null) (s" in $file", file.toString) + else ("", "the signature") + private val name = ctx.fresh.setSetting(ctx.settings.YdebugNames, true).nameString(denot.name) + val msg = hl"""Bad symbolic reference. A signature$location - |refers to $name in ${denotationOwner.showKind} ${denotationOwner.showFullName} which is not available. + |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.""" val explanation = From d779c30f724db2038281e72b290482b5b73b5d01 Mon Sep 17 00:00:00 2001 From: Vitor Vieira Date: Fri, 1 Dec 2017 18:43:36 +0100 Subject: [PATCH 3/4] Ref #1589: Updated based on code review. --- .../dotc/reporting/diagnostic/messages.scala | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 2db877731969..e899ff643314 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -1970,20 +1970,23 @@ object messages { case class BadSymbolicReference(denot: SymDenotation)(implicit ctx: Context) extends Message(BadSymbolicReferenceID) { val kind = "Reference" + private val denotationName = ctx.fresh.setSetting(ctx.settings.YdebugNames, true).nameString(denot.name) - private val file = denot.symbol.associatedFile - private val (location, src) = - if (file != null) (s" in $file", file.toString) - else ("", "the signature") - private val name = ctx.fresh.setSetting(ctx.settings.YdebugNames, true).nameString(denot.name) + val msg = { + val denotationOwner = denot.owner + val file = denot.symbol.associatedFile + val (location, src) = + if (file != null) (s" in $file", file.toString) + else ("", "the signature") - val msg = hl"""Bad symbolic reference. A signature$location - |refers to $name in ${denot.owner.showKind} ${denot.owner.showFullName} which is not available. + |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 = - hl"""A missing or invalid dependency was detected while loading class file '$name'. + hl"""A missing or invalid dependency was detected while loading class file '$denotationName'. |Check your build definition for missing or conflicting dependencies. |Re-run with ${"-Ylog-classpath"} to obtain the information about what classpath is being applied.""" } From db23be8468474d648463269340f280591249ffc0 Mon Sep 17 00:00:00 2001 From: Allan Renucci Date: Mon, 11 Dec 2017 14:48:03 +0100 Subject: [PATCH 4/4] Polishing --- .../dotty/tools/dotc/reporting/diagnostic/messages.scala | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index e899ff643314..484ff1f2f34f 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -1970,10 +1970,10 @@ object messages { case class BadSymbolicReference(denot: SymDenotation)(implicit ctx: Context) extends Message(BadSymbolicReferenceID) { val kind = "Reference" - private val denotationName = ctx.fresh.setSetting(ctx.settings.YdebugNames, true).nameString(denot.name) 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) @@ -1985,10 +1985,7 @@ object messages { |the classpath might be incompatible with the version used when compiling $src.""" } - val explanation = - hl"""A missing or invalid dependency was detected while loading class file '$denotationName'. - |Check your build definition for missing or conflicting dependencies. - |Re-run with ${"-Ylog-classpath"} to obtain the information about what classpath is being applied.""" + val explanation = "" } case class UnableToExtendSealedClass(pclazz: Symbol)(implicit ctx: Context) extends Message(UnableToExtendSealedClassID) {