Skip to content

Fix/catch non fatal #285

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 4 commits into from
Dec 17, 2014
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
12 changes: 4 additions & 8 deletions src/dotty/tools/dotc/Driver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import config.CompilerCommand
import core.Contexts.{Context, ContextBase}
import util.DotClass
import reporting._
import scala.util.control.NonFatal

abstract class Driver extends DotClass {

Expand All @@ -29,14 +30,9 @@ abstract class Driver extends DotClass {
try {
doCompile(newCompiler(), fileNames)
} catch {
case ex: Throwable =>
ex match {
case ex: FatalError =>
ctx.error(ex.getMessage) // signals that we should fail compilation.
ctx.typerState.reporter
case _ =>
throw ex // unexpected error, tell the outside world.
}
case ex: FatalError =>
ctx.error(ex.getMessage) // signals that we should fail compilation.
ctx.typerState.reporter
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ object Denotations {
case info: MethodicType =>
try info.signature
catch { // !!! DEBUG
case ex: Throwable =>
case scala.util.control.NonFatal(ex) =>
println(s"cannot take signature of ${info.show}")
throw ex
}
Expand Down
3 changes: 2 additions & 1 deletion src/dotty/tools/dotc/core/SymbolLoaders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Contexts._, Symbols._, Flags._, SymDenotations._, Types._, Scopes._, util
import StdNames._, NameOps._
import Decorators.{StringDecorator, StringInterpolators}
import pickling.ClassfileParser
import scala.util.control.NonFatal

object SymbolLoaders {
/** A marker trait for a completer that replaces the original
Expand Down Expand Up @@ -206,7 +207,7 @@ abstract class SymbolLoader extends LazyType {
} catch {
case ex: IOException =>
signalError(ex)
case ex: Throwable =>
case NonFatal(ex) =>
println(s"exception caught when loading $root: $ex")
throw ex
} finally {
Expand Down
3 changes: 2 additions & 1 deletion src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import util.{Stats, DotClass, SimpleMap}
import config.Config
import config.Printers._
import TypeErasure.{erasedLub, erasedGlb}
import scala.util.control.NonFatal

/** Provides methods to compare types.
*/
Expand Down Expand Up @@ -401,7 +402,7 @@ class TypeComparer(initctx: Context) extends DotClass {

result
} catch {
case ex: Throwable =>
case NonFatal(ex) =>
def showState = {
println(disambiguated(implicit ctx => s"assertion failure for ${tp1.show} <:< ${tp2.show}, frozen = $frozenConstraint"))
def explainPoly(tp: Type) = tp match {
Expand Down
3 changes: 2 additions & 1 deletion src/dotty/tools/dotc/core/pickling/ClassfileParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import scala.collection.mutable.{ ListBuffer, ArrayBuffer }
import scala.annotation.switch
import typer.Checking.checkNonCyclic
import io.AbstractFile
import scala.util.control.NonFatal

class ClassfileParser(
classfile: AbstractFile,
Expand Down Expand Up @@ -447,7 +448,7 @@ class ClassfileParser(
else Some(Annotation.deferredResolve(attrType, argbuf.toList))
} catch {
case f: FatalError => throw f // don't eat fatal errors, they mean a class was not found
case ex: Throwable =>
case NonFatal(ex) =>
// We want to be robust when annotations are unavailable, so the very least
// we can do is warn the user about the exception
// There was a reference to ticket 1135, but that is outdated: a reference to a class not on
Expand Down
3 changes: 2 additions & 1 deletion src/dotty/tools/dotc/transform/TreeChecker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import util.SourcePosition
import collection.mutable
import ProtoTypes._
import java.lang.AssertionError
import scala.util.control.NonFatal

/** Run by -Ycheck option after a given phase, this class retypes all syntax trees
* and verifies that the type of each tree node so obtained conforms to the type found in the tree node.
Expand Down Expand Up @@ -58,7 +59,7 @@ class TreeChecker {
val checker = new Checker(previousPhases(phasesToRun.toList)(ctx))
try checker.typedExpr(ctx.compilationUnit.tpdTree)(checkingCtx)
catch {
case ex: Throwable =>
case NonFatal(ex) =>
implicit val ctx: Context = checkingCtx
println(i"*** error while checking after phase ${checkingCtx.phase.prev} ***")
throw ex
Expand Down
10 changes: 8 additions & 2 deletions src/dotty/tools/dotc/transform/TreeTransform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import dotty.tools.dotc.core.Decorators._
import dotty.tools.dotc.util.DotClass
import scala.annotation.tailrec
import config.Printers.transforms
import scala.util.control.NonFatal

object TreeTransforms {
import tpd._
Expand Down Expand Up @@ -1215,6 +1216,8 @@ object TreeTransforms {
goOther(tree, info.nx.nxTransOther(cur))
}

private var crashingTree: Tree = EmptyTree

def transform(tree: Tree, info: TransformerInfo, cur: Int)(implicit ctx: Context): Tree = ctx.traceIndented(s"transforming ${tree.show} at ${ctx.phase}", transforms, show = true) {
try
if (cur < info.transformers.length) {
Expand All @@ -1228,8 +1231,11 @@ object TreeTransforms {
}
} else tree
catch {
case ex: Throwable =>
println(i"exception while transforming $tree of class ${tree.getClass} # ${tree.uniqueId}")
case NonFatal(ex) =>
if (tree ne crashingTree) {
crashingTree = tree
println(i"exception while transforming $tree of class ${tree.getClass} # ${tree.uniqueId}")
}
throw ex
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,12 @@ trait Applications extends Compatibility { self: Typer =>
}
}

/** A typed unapply hook, can be overridden by re any-typers between frontend
* and pattern matcher.
*/
def typedUnApply(tree: untpd.UnApply, selType: Type)(implicit ctx: Context) =
throw new UnsupportedOperationException("cannot type check an UnApply node")

/** Is given method reference applicable to type arguments `targs` and argument trees `args`?
* @param resultType The expected result type of the application
*/
Expand Down
3 changes: 2 additions & 1 deletion src/dotty/tools/dotc/typer/FrontEnd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import dotty.tools.dotc.parsing.JavaParsers.JavaParser
import parsing.Parsers.Parser
import config.Printers._
import util.Stats._
import scala.util.control.NonFatal

class FrontEnd extends Phase {

Expand All @@ -16,7 +17,7 @@ class FrontEnd extends Phase {
def monitor(doing: String)(body: => Unit)(implicit ctx: Context) =
try body
catch {
case ex: Throwable =>
case NonFatal(ex) =>
println(s"exception occured while $doing ${ctx.compilationUnit}")
throw ex
}
Expand Down
3 changes: 2 additions & 1 deletion src/dotty/tools/dotc/typer/ReTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Decorators._
import typer.ProtoTypes._
import ast.{tpd, untpd}
import ast.Trees._
import scala.util.control.NonFatal

/** A version of Typer that keeps all symbols defined and referenced in a
* previously typed tree.
Expand Down Expand Up @@ -91,7 +92,7 @@ class ReTyper extends Typer {
override def typedUnadapted(tree: untpd.Tree, pt: Type)(implicit ctx: Context) =
try super.typedUnadapted(tree, pt)
catch {
case ex: Throwable =>
case NonFatal(ex) =>
println(i"exception while typing $tree of class ${tree.getClass} # ${tree.uniqueId}")
throw ex
}
Expand Down
1 change: 1 addition & 0 deletions src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
case tree: untpd.PackageDef => typedPackageDef(tree)
case tree: untpd.Annotated => typedAnnotated(tree, pt)
case tree: untpd.TypedSplice => tree.tree
case tree: untpd.UnApply => typedUnApply(tree, pt)
case untpd.PostfixOp(tree, nme.WILDCARD) => typedAsFunction(tree, pt)
case untpd.EmptyTree => tpd.EmptyTree
case _ => typedUnadapted(desugar(tree), pt)
Expand Down