-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8f04ff
commit 8e4fa2e
Showing
5 changed files
with
95 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
analyzer/src/main/scala/com/avsystem/commons/analyzer/ThrownExceptionNotInFunction.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.avsystem.commons | ||
package analyzer | ||
|
||
import scala.tools.nsc.Global | ||
|
||
final class ThrownExceptionNotInFunction(g: Global) extends AnalyzerRule(g, "thrownExceptionNotInFunction") { | ||
|
||
import global.* | ||
|
||
def analyze(unit: CompilationUnit): Unit = unit.body.foreach(analyzeTree { | ||
case t@Apply(f: TypeApply, List(Throw(_))) if definitions.isFunctionType(f.tpe.params.head.tpe) => | ||
report(t.pos, "exception thrown in place of function definition") | ||
}) | ||
} |
59 changes: 0 additions & 59 deletions
59
analyzer/src/main/scala/com/avsystem/commons/analyzer/ThrownExceptionNotInMonixScope.scala
This file was deleted.
Oops, something went wrong.
80 changes: 80 additions & 0 deletions
80
analyzer/src/test/scala/com/avsystem/commons/analyzer/ThrownExceptionNotInFunctionTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.avsystem.commons | ||
package analyzer | ||
|
||
import org.scalatest.funsuite.AnyFunSuite | ||
|
||
final class ThrownExceptionNotInFunctionTest extends AnyFunSuite with AnalyzerTest { | ||
settings.pluginOptions.value ++= List("AVSystemAnalyzer:-discardedMonixTask") | ||
|
||
Seq( | ||
("Option[_]", "map"), | ||
("List[_]", "map"), | ||
("Seq[_]", "map"), | ||
("Set[_]", "map"), | ||
("Map[_, _]", "map"), | ||
("scala.concurrent.Future[_]", "map"), | ||
("scala.util.Try[_]", "map"), | ||
("Either[_, _]", "map"), | ||
("monix.eval.Task[_]", "map"), | ||
("com.avsystem.commons.misc.Opt[_]", "map"), | ||
("String => Int", "andThen"), | ||
("String => Nothing", "andThen"), | ||
("Nothing => Nothing", "andThen"), | ||
("String => Int", "compose"), | ||
("Seq[_]", "foreach"), | ||
).foreach { case (tpe, function) => | ||
test(s"Testing $function of $tpe") { | ||
assertErrors(10, | ||
//language=Scala | ||
s""" | ||
|object whatever { | ||
| implicit val ec: scala.concurrent.ExecutionContext = ??? // for Future | ||
| | ||
| def sth: $tpe = ??? | ||
| def ex: Exception = ??? | ||
| | ||
| // errors from these | ||
| sth.$function(throw ex) | ||
| | ||
| { | ||
| println(""); sth.$function(throw ex) | ||
| } | ||
| | ||
| if (true) sth.$function(throw ex) else sth.$function(throw ex) | ||
| | ||
| try sth.$function(throw ex) catch { | ||
| case _: Exception => sth.$function(throw ex) | ||
| } finally sth.$function(throw ex) | ||
| | ||
| Seq(1, 2, 3).foreach(_ => sth.$function(throw ex)) | ||
| | ||
| while (true) sth.$function(throw ex) | ||
| | ||
| do sth.$function(throw ex) while (true) | ||
| | ||
| // no errors from these | ||
| sth.$function(_ => throw ex) | ||
| | ||
| { | ||
| println(""); sth.$function(_ => throw ex) | ||
| } | ||
| | ||
| if (true) sth.$function(_ => throw ex) else sth.$function(_ => throw ex) | ||
| | ||
| try sth.$function(_ => throw ex) catch { | ||
| case _: Exception => sth.$function(_ => throw ex) | ||
| } finally sth.$function(_ => throw ex) | ||
| | ||
| Seq(1, 2, 3).foreach(_ => sth.$function(_ => throw ex)) | ||
| | ||
| while (true) sth.$function(_ => throw ex) | ||
| | ||
| do sth.$function(_ => throw ex) while (true) | ||
|} | ||
| | ||
|""".stripMargin | ||
) | ||
} | ||
} | ||
} | ||
|
61 changes: 0 additions & 61 deletions
61
...zer/src/test/scala/com/avsystem/commons/analyzer/ThrownExceptionNotInMonixScopeTest.scala
This file was deleted.
Oops, something went wrong.