Skip to content

Commit f8e707d

Browse files
committed
Add '-deprecation' option to ScoverageCompiler and fix reported deprecation warnings
All warning are macro-related and reported when Scala version is >= 2.11. There were three kinds: 1. scoverage_snippet6266375223143133247.scala:5: warning: macro defs must have explicitly specified return types (inference of Unit from macro impl's c.Expr[Unit] is deprecated and is going to stop working in 2.12) def test = macro testImpl ^ 2. scoverage_snippet6266375223143133247.scala:6: warning: type Context in package macros is deprecated: Use blackbox.Context or whitebox.Context instead def testImpl(c: Context): c.Expr[Unit] = { ^ 3. scoverage_snippet6689360552943102771.scala:6: warning: method literal in trait ExprUtils is deprecated: Use quasiquotes instead def poly[T: c.WeakTypeTag] = c.literal(c.weakTypeOf[T].toString) ^
1 parent 74927af commit f8e707d

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import java.io.File
44

55
trait MacroSupport {
66

7+
val macroContextPackageName: String = if (ScoverageCompiler.ShortScalaVersion == "2.10") {
8+
"scala.reflect.macros"
9+
}
10+
else {
11+
"scala.reflect.macros.blackbox"
12+
}
13+
714
val macroSupportDeps = Seq(testClasses)
815

916
private def testClasses: File = new File(s"./scalac-scoverage-plugin/target/scala-${ScoverageCompiler.ShortScalaVersion}/test-classes")

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ class PluginASTSupportTest
8383

8484
test("scoverage component should ignore basic macros") {
8585
val compiler = ScoverageCompiler.default
86-
compiler.compileCodeSnippet( """
86+
compiler.compileCodeSnippet( s"""
8787
| object MyMacro {
8888
| import scala.language.experimental.macros
89-
| import scala.reflect.macros.Context
90-
| def test = macro testImpl
89+
| import ${macroContextPackageName}.Context
90+
| def test: Unit = macro testImpl
9191
| def testImpl(c: Context): c.Expr[Unit] = {
9292
| import c.universe._
9393
| reify {
@@ -100,12 +100,12 @@ class PluginASTSupportTest
100100

101101
test("scoverage component should ignore complex macros #11") {
102102
val compiler = ScoverageCompiler.default
103-
compiler.compileCodeSnippet( """ object ComplexMacro {
103+
compiler.compileCodeSnippet( s""" object ComplexMacro {
104104
|
105105
| import scala.language.experimental.macros
106-
| import scala.reflect.macros.Context
106+
| import ${macroContextPackageName}.Context
107107
|
108-
| def debug(params: Any*) = macro debugImpl
108+
| def debug(params: Any*): Unit = macro debugImpl
109109
|
110110
| def debugImpl(c: Context)(params: c.Expr[Any]*) = {
111111
| import c.universe._
@@ -114,7 +114,7 @@ class PluginASTSupportTest
114114
| case Literal(Constant(_)) => reify { print(param.splice) }
115115
| case _ => reify {
116116
| val variable = c.Expr[String](Literal(Constant(show(param.tree)))).splice
117-
| print(s"$variable = ${param.splice}")
117+
| print(s"$$variable = $${param.splice}")
118118
| }
119119
| }).tree
120120
| }

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ class PluginCoverageTest
3535
}
3636
3737
object Macros {
38-
def poly[T] = macro Impl.poly[T]
38+
def poly[T]: String = macro Impl.poly[T]
3939
}"""
4040
else
41-
"""
41+
s"""
4242
import scala.language.experimental.macros
43-
import scala.reflect.macros.Context
43+
import scala.reflect.macros.blackbox.Context
4444
class Impl(val c: Context) {
4545
import c.universe._
46-
def poly[T: c.WeakTypeTag] = c.literal(c.weakTypeOf[T].toString)
46+
def poly[T: c.WeakTypeTag] = q"$${c.weakTypeOf[T].toString}"
4747
}
4848
object Macros {
49-
def poly[T] = macro Impl.poly[T]
49+
def poly[T]: String = macro Impl.poly[T]
5050
}"""
5151
compiler.compileCodeSnippet(code)
5252
assert(!compiler.reporter.hasErrors)
@@ -269,11 +269,11 @@ class PluginCoverageTest
269269

270270
test("plugin should not instrument local macro implementation") {
271271
val compiler = ScoverageCompiler.default
272-
compiler.compileCodeSnippet( """
272+
compiler.compileCodeSnippet( s"""
273273
| object MyMacro {
274274
| import scala.language.experimental.macros
275-
| import scala.reflect.macros.Context
276-
| def test = macro testImpl
275+
| import ${macroContextPackageName}.Context
276+
| def test: Unit = macro testImpl
277277
| def testImpl(c: Context): c.Expr[Unit] = {
278278
| import c.universe._
279279
| reify {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ object ScoverageCompiler {
2222
def settings: Settings = {
2323
val s = new scala.tools.nsc.Settings
2424
s.Xprint.value = List("all")
25+
s.deprecation.value = true
2526
s.Yrangepos.value = true
2627
s.Yposdebug.value = true
2728
s.classpath.value = classPath.mkString(File.pathSeparator)

0 commit comments

Comments
 (0)