-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
area:desugarDesugaring happens after parsing but before typing, see desugar.scalaDesugaring happens after parsing but before typing, see desugar.scalaitype:bug
Description
Compiler version
Warning found in: 3.7.4, 3.8.0
Minimized example
While working with utest I got false warnings about unused pattern variables where all were unused. A was able to minimize the error to this self contained example:
Macro:
import scala.quoted.*
object TestBuilder:
transparent inline def test(inline expr: Unit): Any =
${ TestBuilder.processTests('expr) }
def processTests(using Quotes)(body: Expr[Unit]): Expr[Any] =
import quotes.reflect.*
val treeMap = new TreeMap {}
val mapped =
treeMap.transformTerm(body.asTerm)(Symbol.spliceOwner)
mapped.asExprActual file:
object Tests:
TestBuilder.test:
val start @ _: String = "" // Converting this to a match expression resolves the error
// Alternative: val Seq(start) = Seq("")
print(start)Warning message
[warn] -- [E198] Unused Symbol Warning: /.../Test.scala:2:2
[warn] 2 | Builder.test:
[warn] | ^^^^^
[warn] | unused pattern variable
[warn] one warning foundI think this is an error in the compiler, but maybe I got the idea of TreeMap wrong and it's actually an bug in utest.
Observations:
- the number of
^in the warning is equal to the length of the pattern variablestart(5). If I renamestarttoendthe message shows only three^. - If
startis actually unused it's reported correctly at the correct position. mapped.showandbody.asTerm.showproduce the same output. I couldn't figure out what the actual difference between them is.- Returning
body.asTerm.changeOwner(Symbol.spliceOwner).asExprproduces no warning,TreeMapseems to be required.
Why this Error/Warning was not helpful
I think this is a false positive.
Suggested improvement
No warning should be shown here.
Metadata
Metadata
Assignees
Labels
area:desugarDesugaring happens after parsing but before typing, see desugar.scalaDesugaring happens after parsing but before typing, see desugar.scalaitype:bug