Skip to content

Commit e3058ed

Browse files
committed
Added support for nested expressions in new statements
1 parent 051fc70 commit e3058ed

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

scalac-scoverage-plugin/src/main/scala/scoverage/plugin.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class ScoverageInstrumentationComponent(val global: Global)
155155
def instrument(tree: Tree, branch: Boolean = false): Tree = {
156156
safeSource(tree) match {
157157
case None =>
158-
println(s"[warn] [scoverage] Could not instrument [${tree.getClass.getSimpleName}/${tree.symbol}]. No pos.")
158+
println(s"[warn] Could not instrument [${tree.getClass.getSimpleName}/${tree.symbol}]. No pos.")
159159
tree
160160
case Some(source) =>
161161
if (tree.pos.isDefined && !isStatementIncluded(tree.pos)) {
@@ -465,6 +465,8 @@ class ScoverageInstrumentationComponent(val global: Global)
465465
* List(Literal(Constant(3))))
466466
*
467467
*/
468+
case n: New => n
469+
468470
case s@Select(n@New(tpt), name) =>
469471
instrument(treeCopy.Select(s, n, name))
470472

scalac-scoverage-plugin/src/test/scala/scoverage/PluginCoverageTest.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ class PluginCoverageTest
106106

107107
test("scoverage should correctly handle new that invokes nested statements") {
108108
val compiler = ScoverageCompiler.default
109-
compiler.compileCodeSnippet( """ object A {
110-
| new String(if (System.currentTimeMillis > 1) "yes" else "no")
109+
compiler.compileCodeSnippet( """
110+
| object A {
111+
| val value = new java.util.concurrent.CountDownLatch(if (System.currentTimeMillis > 1) 5 else 10)
111112
| } """.stripMargin)
112113
assert(!compiler.reporter.hasErrors)
113114
assert(!compiler.reporter.hasWarnings)

0 commit comments

Comments
 (0)