nvim-treesitter / nvim-treesitter/nvim-treesitter

Mark Java's `instanceof` pattern variables as `@local.definition.var`

Open
#7,828 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Tree-sitter Query
Stars
14.4k
Forks
1.4k
Avg merge
4h 35m
Merged PRs (30d)
13

Description

Java's instanceof pattern matching contains a variable declaration. Take for example o instanceof String s.
In this example the variable s of type String is declared. Therefore, s should be marked as a variable declaration @local.definition.var. It is not.

Scopes
Ideally the variable declaration is also assigned the correct scope. But this seems complicated, because the scope depends on control-flow. The scope specification can be found here. These are some examples illustrating the scopes:

if (e instanceof String s1) {
  System.out.println(s1); // valid
} else {
  System.out.println(s1); // error: s1 not in scope
}
if (!(e instanceof String s2)) {
  System.out.println(s2); // error: s2 not in scope
} else {
  System.out.println(s2); // valid
}
if (!!(e instanceof String s3)) {
  System.out.println(s3); // valid
} else {
  System.out.println(s3); // error: s3 not in scope
}
if (!(e instanceof String s4)) {
  System.out.println(s4); // error: s4 not in scope
  return;
}
System.out.println(s4); // valid

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Java Tree-sitter query handling instanceof pattern variables and read the linked JLS scope specification, especially section 6.3.2. Done means the declared pattern variable is marked with @local.definition.var, with its scope handled where feasible according to the examples in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.