Skip to content

Commit b16682f

Browse files
committed
Fix #3540: Added suggestions from code review.
1 parent 3fa7d58 commit b16682f

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
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
@@ -118,6 +118,7 @@ public enum ErrorMessageID {
118118
UnapplyInvalidNumberOfArgumentsID,
119119
StaticFieldsOnlyAllowedInObjectsID,
120120
CyclicInheritanceID,
121+
BadSymbolicReferenceID,
121122
UnableToExtendSealedClassID,
122123
SymbolHasUnparsableVersionNumberID,
123124
SymbolChangedSemanticsInVersionID,

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,6 +1978,26 @@ object messages {
19781978
}
19791979
}
19801980

1981+
case class BadSymbolicReference(denot: SymDenotation)(implicit ctx: Context) extends Message(BadSymbolicReferenceID) {
1982+
val kind = "Reference"
1983+
1984+
val msg = {
1985+
val denotationOwner = denot.owner
1986+
val denotationName = ctx.fresh.setSetting(ctx.settings.YdebugNames, true).nameString(denot.name)
1987+
val file = denot.symbol.associatedFile
1988+
val (location, src) =
1989+
if (file != null) (s" in $file", file.toString)
1990+
else ("", "the signature")
1991+
1992+
hl"""Bad symbolic reference. A signature$location
1993+
|refers to $denotationName in ${denotationOwner.showKind} ${denotationOwner.showFullName} which is not available.
1994+
|It may be completely missing from the current classpath, or the version on
1995+
|the classpath might be incompatible with the version used when compiling $src."""
1996+
}
1997+
1998+
val explanation = ""
1999+
}
2000+
19812001
case class UnableToExtendSealedClass(pclazz: Symbol)(implicit ctx: Context) extends Message(UnableToExtendSealedClassID) {
19822002
val kind = "Syntax"
19832003
val msg = hl"Cannot extend ${"sealed"} $pclazz in a different source file"

tests/pos/i3540.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
object Test {
22
implicit class Foo(x: Int)(implicit y: Int)
3-
implicit class Foo(x: Int)(y: Int)(implicit z: Int) // OK but not used during implicit lookup
4-
implicit class Foo(x: Int)(y: Int) // OK but not used during implicit lookup
3+
implicit class Foo0(x: Int)(y: Int)(implicit z: Int) // OK but not used during implicit lookup
4+
implicit class Foo1(x: Int)(y: Int) // OK but not used during implicit lookup
55
}

0 commit comments

Comments
 (0)