Skip to content

Commit d1c479f

Browse files
authored
Merge pull request #3748 from dotty-staging/fix-#3187
Fix #3187: Don't crash in requiredClass if class is missing
2 parents 8ab3ce6 + df28080 commit d1c479f

File tree

7 files changed

+32
-179
lines changed

7 files changed

+32
-179
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
@@ -1115,7 +1115,7 @@ object Denotations {
11151115
* Produced by staticRef, consumed by requiredSymbol.
11161116
*/
11171117
case class MissingRef(val owner: SingleDenotation, name: Name)(implicit ctx: Context) extends ErrorDenotation {
1118-
val ex: Exception = new Exception
1118+
val ex: Exception = new Exception // DEBUG
11191119
}
11201120

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

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ trait Symbols { this: Context =>
243243
case name: TypeName =>
244244
newClassSymbol(normalizedOwner, name, EmptyFlags, stubCompleter, assocFile = file)
245245
}
246-
stubs = stub :: stubs
247246
stub
248247
}
249248

@@ -377,7 +376,10 @@ trait Symbols { this: Context =>
377376
def requiredPackageRef(path: PreName): TermRef = requiredPackage(path).termRef
378377

379378
def requiredClass(path: PreName): ClassSymbol =
380-
base.staticRef(path.toTypeName).requiredSymbol(_.isClass).asClass
379+
base.staticRef(path.toTypeName).requiredSymbol(_.isClass) match {
380+
case cls: ClassSymbol => cls
381+
case sym => defn.AnyClass
382+
}
381383

382384
def requiredClassRef(path: PreName): TypeRef = requiredClass(path).typeRef
383385

@@ -700,8 +702,6 @@ object Symbols {
700702
/** The current class */
701703
def currentClass(implicit ctx: Context): ClassSymbol = ctx.owner.enclosingClass.asClass
702704

703-
@sharable var stubs: List[Symbol] = Nil // diagnostic only
704-
705705
/* Mutable map from symbols any T */
706706
class MutableSymbolMap[T](private[Symbols] val value: java.util.IdentityHashMap[Symbol, T]) extends AnyVal {
707707

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
179179
val ex = new BadSignature(
180180
i"""error reading Scala signature of $classRoot from $source:
181181
|error occurred at position $readIndex: $msg""")
182-
if (ctx.debug || true) original.getOrElse(ex).printStackTrace() // temporarily enable printing of original failure signature to debug failing builds
182+
if (ctx.settings.YdebugMissingRefs.value) original.getOrElse(ex).printStackTrace()
183183
throw ex
184184
}
185185

@@ -415,7 +415,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
415415
owner.info.decls.checkConsistent()
416416
if (slowSearch(name).exists)
417417
System.err.println(i"**** slow search found: ${slowSearch(name)}")
418-
if (ctx.debug) Thread.dumpStack()
418+
if (ctx.settings.YdebugMissingRefs.value) Thread.dumpStack()
419419
ctx.newStubSymbol(owner, name, source)
420420
}
421421
}

compiler/test/dotty/tools/ShowClassTests.scala

Lines changed: 0 additions & 154 deletions
This file was deleted.

compiler/test/dotty/tools/showClass.scala

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/neg/i3187.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package scala
2+
3+
// nopos-error
4+
// nopos-error
5+
// nopos-error
6+
// nopos-error
7+
// nopos-error
8+
// nopos-error
9+
// nopos-error
10+
// nopos-error
11+
// nopos-error
12+
// nopos-error
13+
14+
// nopos-error
15+
// nopos-error
16+
// nopos-error
17+
// nopos-error
18+
// nopos-error
19+
// nopos-error
20+
// nopos-error
21+
// nopos-error
22+
23+
object collection

0 commit comments

Comments
 (0)