-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
area:lintingLinting warnings enabled with -W or -XlintLinting warnings enabled with -W or -Xlintitype:bug
Milestone
Description
Compiler version
3.3.0-RC2
Minimized code
This is hard to minimize because it's macro related. I'll add an example macro in a bit, but lets do a thought experiment. Imagine a macro whose job is to generate a method body for a method. We'll call this macro adder
, and it will add together all the Int parameters of the method. It should be implementable via:
def findMethodSymbol(using q: Quotes)(s: q.reflect.Symbol): Symbol =
import quotes.reflect.*
if s.isDefDef then s
else findMethodSymbol(s.owner)
end findMethodSymbol
inline def adder: Int = ${
adderImpl
}
def adderImpl(using Quotes): Expr[Int] =
import quotes.reflect.*
val inputs = findMethodSymbol(Symbol.spliceOwner).tree match
case DefDef(_, params, _, _) =>
params.last match
case TermParamClause(valDefs) =>
valDefs.map(vd => Ref(vd.symbol).asExprOf[Int])
inputs.reduce((exp1, exp2) => '{$exp1 + $exp2})
Its usage will turn
def myMethod(a: Int, b: Int, c: Int) = adder
into
def myMethod(a: Int, b: Int, c: Int) = a + b + c
Right now, the -Wunused
scanning happens too early, and it just sees adder, and the a
, b
, and c
parameters unused. It does not see the transformed result of adder using a
, b
, or c
.
Expectation
I would like, if possible, that the unused analysis is pushed back to after macro expansion, so that macro usage like above doesn't trigger unused explicit parameter
warnings.
ornicar
Metadata
Metadata
Assignees
Labels
area:lintingLinting warnings enabled with -W or -XlintLinting warnings enabled with -W or -Xlintitype:bug