Skip to content

Commit 8f49884

Browse files
committed
SI-6994 Avoid spurious promiscuous catch warning
It was being issued upon re-typechecking of a transformed tree. Now we disable the warning post-typer.
1 parent 6f72ed8 commit 8f49884

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5367,7 +5367,7 @@ trait Typers extends Modes with Adaptations with Tags {
53675367
var block1 = typed(tree.block, pt)
53685368
var catches1 = typedCases(tree.catches, ThrowableClass.tpe, pt)
53695369

5370-
for (cdef <- catches1 if cdef.guard.isEmpty) {
5370+
for (cdef <- catches1 if !isPastTyper && cdef.guard.isEmpty) {
53715371
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.")
53725372
def unbound(t: Tree) = t.symbol == null || t.symbol == NoSymbol
53735373
cdef.pat match {

test/files/pos/t6994.flags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Xfatal-warnings

test/files/pos/t6994.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object Test {
2+
object NF {
3+
def unapply(t: Throwable): Option[Throwable] = None
4+
}
5+
val x = (try { None } catch { case NF(ex) => None }) getOrElse 0
6+
// Was emitting a spurious warning post typer:
7+
// "This catches all Throwables. If this is really intended, use `case ex6 : Throwable` to clear this warning."
8+
}

0 commit comments

Comments
 (0)