@@ -169,7 +169,7 @@ class ScoverageInstrumentationComponent(val global: Global)
169
169
})
170
170
}
171
171
172
- def instrument (tree : Tree , branch : Boolean = false ) = {
172
+ def instrument (tree : Tree , branch : Boolean = false ): Tree = {
173
173
safeSource(tree) match {
174
174
case None =>
175
175
println(s " [warn] Could not instrument [ ${tree.getClass.getSimpleName}/ ${tree.symbol}]. No position. " )
@@ -436,14 +436,21 @@ class ScoverageInstrumentationComponent(val global: Global)
436
436
case l : Literal => instrument(l)
437
437
438
438
// pattern match clauses will be instrumented per case
439
- case m@ Match (clause : Tree , cases : List [CaseDef ]) =>
439
+ case m@ Match (selector : Tree , cases : List [CaseDef ]) =>
440
440
// we can be fairly sure this was generated as part of a for loop
441
- if (m.selector.toString().contains(" check$" )
442
- && m.selector.tpe.annotations.mkString == " unchecked"
443
- && m.cases.last.toString == " case _ => false" ) // todo check these assumptions for 2.11
444
- treeCopy.Match (tree, instrument(clause), transformCases(cases.dropRight(1 )) ++ cases.takeRight(1 ))
445
- else
446
- treeCopy.Match (tree, instrument(clause), transformCases(cases))
441
+ if (selector.toString().contains(" check$" )
442
+ && selector.tpe.annotations.mkString == " unchecked"
443
+ && m.cases.last.toString == " case _ => false" ) {
444
+ // todo check these assumptions for 2.11
445
+ treeCopy.Match (tree, instrument(selector), transformCases(cases.dropRight(1 )) ++ cases.takeRight(1 ))
446
+ } else {
447
+ // import scala.reflect.runtime.universe.{reify, showRaw}
448
+ // val _selector = reify {
449
+ // Match(Annotated(Apply(Select(New(Ident(scala.unchecked)), nme.CONSTRUCTOR), List()),
450
+ // Ident(newTermName("name")))
451
+ // }
452
+ instrument(treeCopy.Match (tree, process(selector), transformCases(cases)))
453
+ }
447
454
448
455
// a synthetic object is a generated object, such as case class companion
449
456
case m : ModuleDef if m.symbol.isSynthetic => super .transform(tree)
@@ -582,4 +589,3 @@ class ScoverageInstrumentationComponent(val global: Global)
582
589
}
583
590
}
584
591
585
-
0 commit comments