Skip to content

Commit 88b6c14

Browse files
committed
Fix #3187: Don't crash in requiredClass if class is missing
Also, issue stacktraces for missing refs only if Y-debug-missing-refs is set. The test case issues error messages without positions, so it is left in `pos`.
1 parent b58799e commit 88b6c14

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class ScalaSettings extends Settings.SettingGroup {
7777
val Ydebug = BooleanSetting("-Ydebug", "Increase the quantity of debugging output.")
7878
val YdebugTrace = BooleanSetting("-Ydebug-trace", "Trace core operations")
7979
val YdebugFlags = BooleanSetting("-Ydebug-flags", "Print all flags of definitions")
80+
val YdebugMissingRefs = BooleanSetting("-Ydebug-missing-refs", "Print a stacktrace when a required symbol is missing")
8081
val YdebugNames = BooleanSetting("-Ydebug-names", "Show internal representation of names")
8182
val YdebugOwners = BooleanSetting("-Ydebug-owners", "Print all owners of definitions (requires -Yprint-syms)")
8283
val YtermConflict = ChoiceSetting("-Yresolve-term-conflict", "strategy", "Resolve term conflicts", List("package", "object", "error"), "error")

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ object Denotations {
277277
disambiguate(p) match {
278278
case m @ MissingRef(ownerd, name) =>
279279
if (generateStubs) {
280-
m.ex.printStackTrace()
280+
if (ctx.settings.YdebugMissingRefs.value) m.ex.printStackTrace()
281281
ctx.newStubSymbol(ownerd.symbol, name, source)
282282
}
283283
else NoSymbol
@@ -1112,7 +1112,7 @@ object Denotations {
11121112
* Produced by staticRef, consumed by requiredSymbol.
11131113
*/
11141114
case class MissingRef(val owner: SingleDenotation, name: Name)(implicit ctx: Context) extends ErrorDenotation {
1115-
val ex: Exception = new Exception
1115+
val ex: Exception = new Exception // DEBUG
11161116
}
11171117

11181118
/** An error denotation that provides more info about alternatives

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,10 @@ trait Symbols { this: Context =>
369369
def requiredPackageRef(path: PreName): TermRef = requiredPackage(path).termRef
370370

371371
def requiredClass(path: PreName): ClassSymbol =
372-
base.staticRef(path.toTypeName).requiredSymbol(_.isClass).asClass
372+
base.staticRef(path.toTypeName).requiredSymbol(_.isClass) match {
373+
case cls: ClassSymbol => cls
374+
case sym => defn.AnyClass
375+
}
373376

374377
def requiredClassRef(path: PreName): TypeRef = requiredClass(path).typeRef
375378

tests/pos/i3187.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package scala
2+
3+
object collection

0 commit comments

Comments
 (0)