tree-sitter-java icon indicating copy to clipboard operation
tree-sitter-java copied to clipboard

Parsing error for annotations on catch parameters

Open theawless opened this issue 7 months ago • 0 comments

Sample:

try {
} catch (T1 | @A3 T2 e) {
}
program [0, 0] - [3, 0]
  try_statement [0, 0] - [2, 1]
    try [0, 0] - [0, 3]
    body: block [0, 4] - [1, 1]
      { [0, 4] - [0, 5]
      } [1, 0] - [1, 1]
    catch_clause [1, 2] - [2, 1]
      catch [1, 2] - [1, 7]
      ( [1, 8] - [1, 9]
      catch_formal_parameter [1, 9] - [1, 20]
        catch_type [1, 9] - [1, 17]
          type_identifier [1, 9] - [1, 11]
          | [1, 12] - [1, 13]
          ERROR [1, 14] - [1, 15]
            @ [1, 14] - [1, 15]
          type_identifier [1, 15] - [1, 17]
        name: identifier [1, 18] - [1, 20]
      ERROR [1, 21] - [1, 22]
        identifier [1, 21] - [1, 22]
      ) [1, 22] - [1, 23]
      body: block [1, 24] - [2, 1]
        { [1, 24] - [1, 25]
        } [2, 0] - [2, 1]

I noticed that if I add an annotation on T1, that works fine probably because it's considered a modifier.

But it breaks when I add an annotation on T2, which is valid syntax according to JLS: https://docs.oracle.com/javase/specs/jls/se24/html/jls-14.html#jls-CatchType

theawless avatar Jun 10 '25 23:06 theawless