Skip to content

Commit fa07b41

Browse files
committed
Add test cases for macro wunused
1 parent 3b5491e commit fa07b41

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import scala.quoted.*
2+
3+
def findMethodSymbol(using q: Quotes)(s: quotes.reflect.Symbol): quotes.reflect.Symbol =
4+
if s.isDefDef then
5+
s
6+
else
7+
findMethodSymbol(using q)(s.owner)
8+
end findMethodSymbol
9+
10+
11+
inline def adder: Int = ${
12+
adderImpl
13+
}
14+
15+
def adderImpl(using q: Quotes): Expr[Int] =
16+
import quotes.reflect.*
17+
18+
val inputs = findMethodSymbol(using q)(q.reflect.Symbol.spliceOwner).tree match
19+
case DefDef(_, params, _, _) =>
20+
params.last match
21+
case TermParamClause(valDefs) =>
22+
valDefs.map(vd => Ref(vd.symbol).asExprOf[Int])
23+
inputs.reduce((exp1, exp2) => '{ $exp1 + $exp2 })
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// scalac: -Wunused:all
2+
3+
object Foo {
4+
private def myMethod(a: Int, b: Int, c: Int) = adder // ok
5+
myMethod(1, 2, 3)
6+
7+
private def myMethodFailing(a: Int, b: Int, c: Int) = a + 0 // error // error
8+
myMethodFailing(1, 2, 3)
9+
}
10+
11+

0 commit comments

Comments
 (0)