summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2012-06-22 00:42:39 -0700
committerAdriaan Moors <adriaan.moors@epfl.ch>2012-06-22 00:42:39 -0700
commitcfc0e18dc55b33274c1275c192ade4a8d707d635 (patch)
treeed500a8374b7911fe3b6a7443784764fcd231022 /src/compiler
parentff016002738580a7de11977c91e0061dbcf270ad (diff)
parent7d8527b40a3bd6d93cf155b39ee50577751f3e91 (diff)
downloadscala-cfc0e18dc55b33274c1275c192ade4a8d707d635.tar.gz
scala-cfc0e18dc55b33274c1275c192ade4a8d707d635.tar.bz2
scala-cfc0e18dc55b33274c1275c192ade4a8d707d635.zip
Merge pull request #752 from retronym/topic/warn-catch-all-4
SI-2807 Resurrect and refine the promiscuous catch warning.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index b12ca4f0b4..69d3fd7f47 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -4863,6 +4863,16 @@ trait Typers extends Modes with Adaptations with Tags {
case Try(block, catches, finalizer) =>
var block1 = typed(block, pt)
var catches1 = typedCases(catches, ThrowableClass.tpe, pt)
+
+ for (cdef <- catches1 if cdef.guard.isEmpty) {
+ def warn(name: Name) = context.warning(cdef.pat.pos, s"This catches all Throwables. If this is really intended, use `case ${name.decoded} : Throwable` to clear this warning.")
+ cdef.pat match {
+ case Bind(name, Ident(_)) => warn(name)
+ case Ident(name) => warn(name)
+ case _ =>
+ }
+ }
+
val finalizer1 = if (finalizer.isEmpty) finalizer
else typed(finalizer, UnitClass.tpe)
val (owntype, needAdapt) = ptOrLub(block1.tpe :: (catches1 map (_.tpe)), pt)