scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

Syntax error when marking untupled param as @unused

Open raquo opened this issue 1 week ago • 8 comments

Compiler version

3.3.7, 3.8.1-RC1-bin-20251129-7eab684-NIGHTLY

Minimized code

//> using scala 3.3.7
//> using options -Wunused:all

import scala.annotation.unused

val transforms: Seq[(String, Int)] = Nil
transforms.foreach((str, @unused int) => println(str))

Output

-- [E018] Syntax Error: --------------------------------------------------------
7 |transforms.foreach((str, @unused int) => println(str))
  |                         ^
  |                         expression expected but @ found
  |
  | longer explanation available when compiling with `-explain`

Expectation

If I omit @unused, the compiler warns about int being "unused local definition", as expected.

To resolve this, I should be able to add @unused annotation to int, but doing so causes the syntax error above.

Workaround: rename int to _ – but that's inconvenient because I have commented-out code that refers to int.

I'm not sure if this is a bug or feature request, but I think the @unused syntax should work with untupled parameters the same as it does in other contexts.

Also, I was sort of half-expecting the warning to call out "unused explicit parameter" rather than "unused local definition". Doesn't make a difference to me, but might for people who set only one of -Wunused:local and -Wunused:param options.

raquo avatar Nov 30 '25 02:11 raquo