Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10693 from som-snytt/issue/12953-unliftable-unapply
For macros look for usages in expansion by default
- Loading branch information
Showing
21 changed files
with
233 additions
and
26 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
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
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
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
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
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,9 @@ | ||
Client_2.scala:10: warning: possible missing interpolator: detected interpolated identifier `$unusedVariable` | ||
println("hello, world of $unusedVariable") | ||
^ | ||
Client_2.scala:9: warning: local val unusedVariable in value <local Test> is never used | ||
val unusedVariable = "42".toInt | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
2 warnings | ||
1 error |
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,13 @@ | ||
|
||
//> using options -Werror -Wunused:locals -Xlint:missing-interpolator -Wmacros:before | ||
|
||
import Macro.id | ||
|
||
object Test extends App { | ||
println { | ||
id { | ||
val unusedVariable = "42".toInt | ||
println("hello, world of $unusedVariable") | ||
} | ||
} | ||
} |
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,11 @@ | ||
|
||
import scala.language.experimental.macros | ||
import scala.reflect.macros.blackbox.Context | ||
|
||
object Macro { | ||
def id[A](body: A): A = macro impl[A] | ||
|
||
def impl[A: c.WeakTypeTag](c: Context)(body: c.Expr[A]) = { | ||
body | ||
} | ||
} |
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,9 @@ | ||
Client_2.scala:8: warning: possible missing interpolator: detected interpolated identifier `$unusedVariable` | ||
id { | ||
^ | ||
Client_2.scala:8: warning: local val unusedVariable in value <local Test> is never used | ||
id { | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
2 warnings | ||
1 error |
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,12 @@ | ||
|
||
//> using options -Werror -Wunused:locals -Xlint:missing-interpolator -Wmacros:after | ||
|
||
import Macro.id | ||
|
||
object Test extends App { | ||
println { | ||
id { | ||
println("goodbye, cruel world of $unusedVariable") | ||
} | ||
} | ||
} |
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,13 @@ | ||
|
||
import scala.language.experimental.macros | ||
import scala.reflect.macros.blackbox.Context | ||
|
||
// with unused interpolator check in typer, the variable and literal must be typechecked together to warn | ||
object Macro { | ||
def id[A](body: A): A = macro impl[A] | ||
|
||
def impl[A: c.WeakTypeTag](c: Context)(body: c.Expr[A]) = { | ||
import c.universe._ | ||
q"""val unusedVariable = "42".toInt; println("hello, world of $$unusedVariable"); $body""" | ||
} | ||
} |
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,6 @@ | ||
Client_2.scala:8: warning: local val unusedVariable in value <local Test> is never used | ||
id { | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
1 warning | ||
1 error |
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,12 @@ | ||
|
||
//> using options -Werror -Wunused:locals -Xlint:missing-interpolator -Wmacros:after | ||
|
||
import Macro.id | ||
|
||
object Test extends App { | ||
println { | ||
id { | ||
println("hello, world of $unusedVariable") | ||
} | ||
} | ||
} |
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,13 @@ | ||
|
||
import scala.language.experimental.macros | ||
import scala.reflect.macros.blackbox.Context | ||
|
||
// with unused interpolator check in typer, the variable and literal must be typechecked together to warn | ||
object Macro { | ||
def id[A](body: A): A = macro impl[A] | ||
|
||
def impl[A: c.WeakTypeTag](c: Context)(body: c.Expr[A]) = { | ||
import c.universe._ | ||
q"""val unusedVariable = "42".toInt; $body""" | ||
} | ||
} |
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,22 @@ | ||
//> using options -Ymacro-annotations | ||
import scala.language.experimental.macros | ||
import scala.reflect.macros.blackbox.Context | ||
import scala.annotation.StaticAnnotation | ||
|
||
object Macros { | ||
def annotImpl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = { | ||
import c.universe._ | ||
val classTree = annottees.head.tree | ||
val objectTree = q""" | ||
object X { | ||
def f: Int => String = { x => "hello" } | ||
} | ||
""" | ||
|
||
c.Expr[Any](Block(List(classTree, objectTree), Literal(Constant(())))) | ||
} | ||
} | ||
|
||
class mymacro extends StaticAnnotation { | ||
def macroTransform(annottees: Any*): Any = macro Macros.annotImpl | ||
} |
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,7 @@ | ||
//> using options -Ymacro-annotations -Werror -Wmacros:before -Wunused:params | ||
@mymacro | ||
class X | ||
|
||
object Test { | ||
println(X.f(123)) | ||
} |
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
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
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,12 @@ | ||
|
||
//> using options -Werror -Wunused:locals -Xlint:missing-interpolator -Wmacros:default | ||
|
||
import Macro.id | ||
|
||
object Test extends App { | ||
println { | ||
id { | ||
println("hello, world of $unusedVariable") | ||
} | ||
} | ||
} |
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,12 @@ | ||
|
||
import scala.language.experimental.macros | ||
import scala.reflect.macros.blackbox.Context | ||
|
||
object Macro { | ||
def id[A](body: A): A = macro impl[A] | ||
|
||
def impl[A: c.WeakTypeTag](c: Context)(body: c.Expr[A]) = { | ||
import c.universe._ | ||
q"""val unusedVariable = "42".toInt; $body""" | ||
} | ||
} |
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,24 @@ | ||
|
||
//> using options -Werror -Wunused:privates | ||
|
||
package example | ||
|
||
import scala.reflect.macros.blackbox | ||
|
||
/*case*/ class A(x: Int) | ||
|
||
class MyMacro(val c: blackbox.Context) { | ||
import c.universe._ | ||
|
||
def impl(tree: c.Tree): Tree = { | ||
tree match { | ||
case q"${a: A}" => | ||
//reify(a).tree // uses $m in expansion | ||
reify(()).tree | ||
case _ => | ||
c.abort(c.enclosingPosition, "err") | ||
} | ||
} | ||
|
||
private implicit def instance: Unliftable[A] = ??? | ||
} |