Skip to content

Syntax error when marking untupled param as @unused #24592

@raquo

Description

@raquo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    itype:bugstat:needs triageEvery issue needs to have an "area" and "itype" label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions