Skip to content

Fix #3187: Don't crash in requiredClass if class is missing #3748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class ScalaSettings extends Settings.SettingGroup {
val Ydebug = BooleanSetting("-Ydebug", "Increase the quantity of debugging output.")
val YdebugTrace = BooleanSetting("-Ydebug-trace", "Trace core operations")
val YdebugFlags = BooleanSetting("-Ydebug-flags", "Print all flags of definitions")
val YdebugMissingRefs = BooleanSetting("-Ydebug-missing-refs", "Print a stacktrace when a required symbol is missing")
val YdebugNames = BooleanSetting("-Ydebug-names", "Show internal representation of names")
val YdebugOwners = BooleanSetting("-Ydebug-owners", "Print all owners of definitions (requires -Yprint-syms)")
val YtermConflict = ChoiceSetting("-Yresolve-term-conflict", "strategy", "Resolve term conflicts", List("package", "object", "error"), "error")
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ object Denotations {
disambiguate(p) match {
case m @ MissingRef(ownerd, name) =>
if (generateStubs) {
m.ex.printStackTrace()
if (ctx.settings.YdebugMissingRefs.value) m.ex.printStackTrace()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctx.newStubSymbol(ownerd.symbol, name, source)
}
else NoSymbol
Expand Down Expand Up @@ -1115,7 +1115,7 @@ object Denotations {
* Produced by staticRef, consumed by requiredSymbol.
*/
case class MissingRef(val owner: SingleDenotation, name: Name)(implicit ctx: Context) extends ErrorDenotation {
val ex: Exception = new Exception
val ex: Exception = new Exception // DEBUG
}

/** An error denotation that provides more info about alternatives
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ trait Symbols { this: Context =>
case name: TypeName =>
newClassSymbol(normalizedOwner, name, EmptyFlags, stubCompleter, assocFile = file)
}
stubs = stub :: stubs
stub
}

Expand Down Expand Up @@ -369,7 +368,10 @@ trait Symbols { this: Context =>
def requiredPackageRef(path: PreName): TermRef = requiredPackage(path).termRef

def requiredClass(path: PreName): ClassSymbol =
base.staticRef(path.toTypeName).requiredSymbol(_.isClass).asClass
base.staticRef(path.toTypeName).requiredSymbol(_.isClass) match {
case cls: ClassSymbol => cls
case sym => defn.AnyClass
}

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

Expand Down Expand Up @@ -692,8 +694,6 @@ object Symbols {
/** The current class */
def currentClass(implicit ctx: Context): ClassSymbol = ctx.owner.enclosingClass.asClass

@sharable var stubs: List[Symbol] = Nil // diagnostic only

/* Mutable map from symbols any T */
class MutableSymbolMap[T](private[Symbols] val value: java.util.IdentityHashMap[Symbol, T]) extends AnyVal {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
val ex = new BadSignature(
i"""error reading Scala signature of $classRoot from $source:
|error occurred at position $readIndex: $msg""")
if (ctx.debug || true) original.getOrElse(ex).printStackTrace() // temporarily enable printing of original failure signature to debug failing builds
if (ctx.settings.YdebugMissingRefs.value) original.getOrElse(ex).printStackTrace()
throw ex
}

Expand Down Expand Up @@ -415,7 +415,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
owner.info.decls.checkConsistent()
if (slowSearch(name).exists)
System.err.println(i"**** slow search found: ${slowSearch(name)}")
if (ctx.debug) Thread.dumpStack()
if (ctx.settings.YdebugMissingRefs.value) Thread.dumpStack()
ctx.newStubSymbol(owner, name, source)
}
}
Expand Down
154 changes: 0 additions & 154 deletions compiler/test/dotty/tools/ShowClassTests.scala

This file was deleted.

17 changes: 0 additions & 17 deletions compiler/test/dotty/tools/showClass.scala

This file was deleted.

23 changes: 23 additions & 0 deletions tests/neg/i3187.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package scala

// nopos-error
// nopos-error
// nopos-error
// nopos-error
// nopos-error
// nopos-error
// nopos-error
// nopos-error
// nopos-error
// nopos-error

// nopos-error
// nopos-error
// nopos-error
// nopos-error
// nopos-error
// nopos-error
// nopos-error
// nopos-error

object collection