Skip to content

Commit 04ff725

Browse files
committed
support NonFatal alias also
1 parent 441f2f6 commit 04ff725

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

analyzer/src/main/scala/com/avsystem/commons/analyzer/CatchThrowable.scala

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ class CatchThrowable(g: Global) extends AnalyzerRule(g, "catchThrowable", Level.
99
import global._
1010

1111
private lazy val throwableTpe = typeOf[Throwable]
12-
private lazy val nonFatalSym = typeOf[NonFatal.type].termSymbol
12+
13+
private lazy val nonFatalSymbols = {
14+
val nonFatal = typeOf[NonFatal.type].termSymbol
15+
val nonFatalAlias = classType("com.avsystem.commons.CommonAliases").member(TermName("NonFatal"))
16+
17+
Set(nonFatal, nonFatalAlias)
18+
}
1319

1420
private def isNonFatalPattern(tree: Tree): Boolean = tree match {
15-
case UnApply(Apply(Select(qualifier, TermName("unapply")), _), _) if qualifier.symbol == nonFatalSym => true
21+
case UnApply(Apply(Select(qualifier, TermName("unapply")), _), _) if nonFatalSymbols contains qualifier.symbol => true
1622
case _ => false
1723
}
1824

analyzer/src/test/scala/com/avsystem/commons/analyzer/CatchThrowableTest.scala

+2-3
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,13 @@ class CatchThrowableTest extends AnyFunSuite with AnalyzerTest {
7777
assertNoErrors(
7878
//language=Scala
7979
"""
80-
|import scala.util.control.NonFatal
81-
|
82-
|object Test {
80+
|object Test extends com.avsystem.commons.CommonAliases {
8381
| def test(): Unit = {
8482
| try {
8583
| println("test")
8684
| } catch {
8785
| case NonFatal(t) => println(t)
86+
| case scala.util.control.NonFatal(t) => println(t)
8887
| }
8988
| }
9089
|}

0 commit comments

Comments
 (0)