Skip to content

Commit 33ebbb8

Browse files
vitorsvieiraallanrenucci
authored andcommitted
Ref #1589: Add error message for bad symbolic reference. (#3605)
1 parent 7e919b6 commit 33ebbb8

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import util.Stats
1818
import java.util.WeakHashMap
1919
import config.Config
2020
import config.Printers.{incremental, noPrinter}
21+
import reporting.diagnostic.Message
22+
import reporting.diagnostic.messages.BadSymbolicReference
2123
import reporting.trace
2224

2325
trait SymDenotations { this: Context =>
@@ -1956,7 +1958,7 @@ object SymDenotations {
19561958
/** A completer for missing references */
19571959
class StubInfo() extends LazyType {
19581960

1959-
def initializeToDefaults(denot: SymDenotation, errMsg: => String)(implicit ctx: Context) = {
1961+
def initializeToDefaults(denot: SymDenotation, errMsg: => Message)(implicit ctx: Context): Unit = {
19601962
denot.info = denot match {
19611963
case denot: ClassDenotation =>
19621964
ClassInfo(denot.owner.thisType, denot.classSymbol, Nil, EmptyScope)
@@ -1968,18 +1970,9 @@ object SymDenotations {
19681970

19691971
def complete(denot: SymDenotation)(implicit ctx: Context): Unit = {
19701972
val sym = denot.symbol
1971-
val file = sym.associatedFile
1972-
val (location, src) =
1973-
if (file != null) (s" in $file", file.toString)
1974-
else ("", "the signature")
1975-
val name = ctx.fresh.setSetting(ctx.settings.YdebugNames, true).nameString(denot.name)
1976-
def errMsg =
1977-
i"""bad symbolic reference. A signature$location
1978-
|refers to $name in ${denot.owner.showKind} ${denot.owner.showFullName} which is not available.
1979-
|It may be completely missing from the current classpath, or the version on
1980-
|the classpath might be incompatible with the version used when compiling $src."""
1981-
ctx.error(errMsg)
1982-
if (ctx.debug) throw new Error()
1973+
def errMsg = BadSymbolicReference(denot)
1974+
ctx.error(errMsg, sym.pos)
1975+
if (ctx.debug) throw new scala.Error()
19831976
initializeToDefaults(denot, errMsg)
19841977
}
19851978
}

compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public enum ErrorMessageID {
117117
UnapplyInvalidNumberOfArgumentsID,
118118
StaticFieldsOnlyAllowedInObjectsID,
119119
CyclicInheritanceID,
120+
BadSymbolicReferenceID,
120121
UnableToExtendSealedClassID,
121122
SymbolHasUnparsableVersionNumberID,
122123
SymbolChangedSemanticsInVersionID,

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,6 +1963,26 @@ object messages {
19631963
}
19641964
}
19651965

1966+
case class BadSymbolicReference(denot: SymDenotation)(implicit ctx: Context) extends Message(BadSymbolicReferenceID) {
1967+
val kind = "Reference"
1968+
1969+
val msg = {
1970+
val denotationOwner = denot.owner
1971+
val denotationName = ctx.fresh.setSetting(ctx.settings.YdebugNames, true).nameString(denot.name)
1972+
val file = denot.symbol.associatedFile
1973+
val (location, src) =
1974+
if (file != null) (s" in $file", file.toString)
1975+
else ("", "the signature")
1976+
1977+
hl"""Bad symbolic reference. A signature$location
1978+
|refers to $denotationName in ${denotationOwner.showKind} ${denotationOwner.showFullName} which is not available.
1979+
|It may be completely missing from the current classpath, or the version on
1980+
|the classpath might be incompatible with the version used when compiling $src."""
1981+
}
1982+
1983+
val explanation = ""
1984+
}
1985+
19661986
case class UnableToExtendSealedClass(pclazz: Symbol)(implicit ctx: Context) extends Message(UnableToExtendSealedClassID) {
19671987
val kind = "Syntax"
19681988
val msg = hl"Cannot extend ${"sealed"} $pclazz in a different source file"

0 commit comments

Comments
 (0)