Skip to content

Commit f052b1e

Browse files
committed
#45 Fixing final vals in annotations
1 parent 337666b commit f052b1e

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

src/main/scala/scoverage/plugin.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ class ScoveragePreComponent(val global: Global) extends PluginComponent with Typ
6666
class Transformer(unit: global.CompilationUnit) extends TypingTransformer(unit) {
6767
override def transform(tree: Tree) = {
6868
tree match {
69-
case v: ValDef if v.mods.isFinal =>
70-
treeCopy.ValDef(v, v.mods.&~(ModifierFlags.FINAL), v.name, v.tpt, v.rhs)
69+
// case v: ValDef if v.mods.isFinal =>
70+
// treeCopy.ValDef(v, v.mods.&~(ModifierFlags.FINAL), v.name, v.tpt, v.rhs)
7171
case _ =>
7272
super.transform(tree)
7373
}

src/main/scala/scoverage/report/CodeGrid.scala

100755100644
File mode changed.

src/test/scala/scoverage/PluginASTSupportTest.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ class PluginASTSupportTest
8989
assert(!reporter.hasWarnings)
9090
}
9191

92+
// https://github.com/scoverage/scalac-scoverage-plugin/issues/45
93+
test("compile final vals in annotations") {
94+
compileCodeSnippet( """object Foo {
95+
| final val foo = 1L
96+
|}
97+
|@SerialVersionUID(value = Foo.foo)
98+
|class Bar
99+
|""".stripMargin)
100+
assert(!reporter.hasErrors)
101+
assert(!reporter.hasWarnings)
102+
}
103+
92104
//test("type param with default arg supported") {
93105
// compileCodeSnippet( """ class TypeTreeObjects {
94106
// | class Container {

src/test/scala/scoverage/PluginCoverageTest.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,19 @@ class PluginCoverageTest
2323
assertNMeasuredStatements(2)
2424
}
2525

26-
test("scoverage should instrument private final vals") {
26+
test("scoverage should instrument final vals") {
2727
compileCodeSnippet( """ object FinalVals {
28-
| private final val name = "sammy"
28+
| final val name = {
29+
| val name = "sammy"
30+
| if (System.currentTimeMillis() > 0) {
31+
| println(name)
32+
| }
33+
| }
2934
| println(name)
3035
|} """.stripMargin)
3136
assert(!reporter.hasErrors)
3237
// we should have 3 statements - initialising the val, executing println, and executing the parameter
33-
assertNMeasuredStatements(3)
38+
assertNMeasuredStatements(8)
3439
}
3540

3641
test("scoverage should instrument selectors in match") {

0 commit comments

Comments
 (0)