Skip to content

Commit ecbf5f5

Browse files
committed
Merge pull request #285 from dotty-staging/fix/catchNonFatal
Fix/catch non fatal
2 parents 3a68e50 + 625ad7f commit ecbf5f5

File tree

11 files changed

+32
-17
lines changed

11 files changed

+32
-17
lines changed

src/dotty/tools/dotc/Driver.scala

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import config.CompilerCommand
44
import core.Contexts.{Context, ContextBase}
55
import util.DotClass
66
import reporting._
7+
import scala.util.control.NonFatal
78

89
abstract class Driver extends DotClass {
910

@@ -29,14 +30,9 @@ abstract class Driver extends DotClass {
2930
try {
3031
doCompile(newCompiler(), fileNames)
3132
} catch {
32-
case ex: Throwable =>
33-
ex match {
34-
case ex: FatalError =>
35-
ctx.error(ex.getMessage) // signals that we should fail compilation.
36-
ctx.typerState.reporter
37-
case _ =>
38-
throw ex // unexpected error, tell the outside world.
39-
}
33+
case ex: FatalError =>
34+
ctx.error(ex.getMessage) // signals that we should fail compilation.
35+
ctx.typerState.reporter
4036
}
4137
}
4238

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ object Denotations {
386386
case info: MethodicType =>
387387
try info.signature
388388
catch { // !!! DEBUG
389-
case ex: Throwable =>
389+
case scala.util.control.NonFatal(ex) =>
390390
println(s"cannot take signature of ${info.show}")
391391
throw ex
392392
}

src/dotty/tools/dotc/core/SymbolLoaders.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Contexts._, Symbols._, Flags._, SymDenotations._, Types._, Scopes._, util
1414
import StdNames._, NameOps._
1515
import Decorators.{StringDecorator, StringInterpolators}
1616
import pickling.ClassfileParser
17+
import scala.util.control.NonFatal
1718

1819
object SymbolLoaders {
1920
/** A marker trait for a completer that replaces the original
@@ -206,7 +207,7 @@ abstract class SymbolLoader extends LazyType {
206207
} catch {
207208
case ex: IOException =>
208209
signalError(ex)
209-
case ex: Throwable =>
210+
case NonFatal(ex) =>
210211
println(s"exception caught when loading $root: $ex")
211212
throw ex
212213
} finally {

src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import util.{Stats, DotClass, SimpleMap}
1212
import config.Config
1313
import config.Printers._
1414
import TypeErasure.{erasedLub, erasedGlb}
15+
import scala.util.control.NonFatal
1516

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

402403
result
403404
} catch {
404-
case ex: Throwable =>
405+
case NonFatal(ex) =>
405406
def showState = {
406407
println(disambiguated(implicit ctx => s"assertion failure for ${tp1.show} <:< ${tp2.show}, frozen = $frozenConstraint"))
407408
def explainPoly(tp: Type) = tp match {

src/dotty/tools/dotc/core/pickling/ClassfileParser.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import scala.collection.mutable.{ ListBuffer, ArrayBuffer }
1313
import scala.annotation.switch
1414
import typer.Checking.checkNonCyclic
1515
import io.AbstractFile
16+
import scala.util.control.NonFatal
1617

1718
class ClassfileParser(
1819
classfile: AbstractFile,
@@ -447,7 +448,7 @@ class ClassfileParser(
447448
else Some(Annotation.deferredResolve(attrType, argbuf.toList))
448449
} catch {
449450
case f: FatalError => throw f // don't eat fatal errors, they mean a class was not found
450-
case ex: Throwable =>
451+
case NonFatal(ex) =>
451452
// We want to be robust when annotations are unavailable, so the very least
452453
// we can do is warn the user about the exception
453454
// There was a reference to ticket 1135, but that is outdated: a reference to a class not on

src/dotty/tools/dotc/transform/TreeChecker.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import util.SourcePosition
2323
import collection.mutable
2424
import ProtoTypes._
2525
import java.lang.AssertionError
26+
import scala.util.control.NonFatal
2627

2728
/** Run by -Ycheck option after a given phase, this class retypes all syntax trees
2829
* and verifies that the type of each tree node so obtained conforms to the type found in the tree node.
@@ -58,7 +59,7 @@ class TreeChecker {
5859
val checker = new Checker(previousPhases(phasesToRun.toList)(ctx))
5960
try checker.typedExpr(ctx.compilationUnit.tpdTree)(checkingCtx)
6061
catch {
61-
case ex: Throwable =>
62+
case NonFatal(ex) =>
6263
implicit val ctx: Context = checkingCtx
6364
println(i"*** error while checking after phase ${checkingCtx.phase.prev} ***")
6465
throw ex

src/dotty/tools/dotc/transform/TreeTransform.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import dotty.tools.dotc.core.Decorators._
1616
import dotty.tools.dotc.util.DotClass
1717
import scala.annotation.tailrec
1818
import config.Printers.transforms
19+
import scala.util.control.NonFatal
1920

2021
object TreeTransforms {
2122
import tpd._
@@ -1215,6 +1216,8 @@ object TreeTransforms {
12151216
goOther(tree, info.nx.nxTransOther(cur))
12161217
}
12171218

1219+
private var crashingTree: Tree = EmptyTree
1220+
12181221
def transform(tree: Tree, info: TransformerInfo, cur: Int)(implicit ctx: Context): Tree = ctx.traceIndented(s"transforming ${tree.show} at ${ctx.phase}", transforms, show = true) {
12191222
try
12201223
if (cur < info.transformers.length) {
@@ -1228,8 +1231,11 @@ object TreeTransforms {
12281231
}
12291232
} else tree
12301233
catch {
1231-
case ex: Throwable =>
1232-
println(i"exception while transforming $tree of class ${tree.getClass} # ${tree.uniqueId}")
1234+
case NonFatal(ex) =>
1235+
if (tree ne crashingTree) {
1236+
crashingTree = tree
1237+
println(i"exception while transforming $tree of class ${tree.getClass} # ${tree.uniqueId}")
1238+
}
12331239
throw ex
12341240
}
12351241
}

src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,12 @@ trait Applications extends Compatibility { self: Typer =>
763763
}
764764
}
765765

766+
/** A typed unapply hook, can be overridden by re any-typers between frontend
767+
* and pattern matcher.
768+
*/
769+
def typedUnApply(tree: untpd.UnApply, selType: Type)(implicit ctx: Context) =
770+
throw new UnsupportedOperationException("cannot type check an UnApply node")
771+
766772
/** Is given method reference applicable to type arguments `targs` and argument trees `args`?
767773
* @param resultType The expected result type of the application
768774
*/

src/dotty/tools/dotc/typer/FrontEnd.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import dotty.tools.dotc.parsing.JavaParsers.JavaParser
88
import parsing.Parsers.Parser
99
import config.Printers._
1010
import util.Stats._
11+
import scala.util.control.NonFatal
1112

1213
class FrontEnd extends Phase {
1314

@@ -16,7 +17,7 @@ class FrontEnd extends Phase {
1617
def monitor(doing: String)(body: => Unit)(implicit ctx: Context) =
1718
try body
1819
catch {
19-
case ex: Throwable =>
20+
case NonFatal(ex) =>
2021
println(s"exception occured while $doing ${ctx.compilationUnit}")
2122
throw ex
2223
}

src/dotty/tools/dotc/typer/ReTyper.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Decorators._
99
import typer.ProtoTypes._
1010
import ast.{tpd, untpd}
1111
import ast.Trees._
12+
import scala.util.control.NonFatal
1213

1314
/** A version of Typer that keeps all symbols defined and referenced in a
1415
* previously typed tree.
@@ -91,7 +92,7 @@ class ReTyper extends Typer {
9192
override def typedUnadapted(tree: untpd.Tree, pt: Type)(implicit ctx: Context) =
9293
try super.typedUnadapted(tree, pt)
9394
catch {
94-
case ex: Throwable =>
95+
case NonFatal(ex) =>
9596
println(i"exception while typing $tree of class ${tree.getClass} # ${tree.uniqueId}")
9697
throw ex
9798
}

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
10211021
case tree: untpd.PackageDef => typedPackageDef(tree)
10221022
case tree: untpd.Annotated => typedAnnotated(tree, pt)
10231023
case tree: untpd.TypedSplice => tree.tree
1024+
case tree: untpd.UnApply => typedUnApply(tree, pt)
10241025
case untpd.PostfixOp(tree, nme.WILDCARD) => typedAsFunction(tree, pt)
10251026
case untpd.EmptyTree => tpd.EmptyTree
10261027
case _ => typedUnadapted(desugar(tree), pt)

0 commit comments

Comments
 (0)