LocalVariable: no identity for the declaration, so same-named locals in sibling scopes are one variable
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 28/100
調査の方向性
Start by reading LocalVariableImpl and the Variable interface, especially the existing assignmentExpression() contract and the equality assumptions described in the issue. Then trace how the parser represents local declarations and how variable reads are resolved, including for-each, catch, and pattern declarations. The issue proposes declaration identity or a scope-qualified name; done means same-named locals from separate declarations can be distinguished by callers without changing equals.
索引モデルが issue の本文から書いたものです。
説明
What is missing
LocalVariableImpl documents it: a local's FQN is its bare name, so equals/hashCode make two same-named locals from different scopes equal. The note gives the two invariants under which that is safe for the analyzers (scope-disjoint locals never coexist in a per-statement structure; graphs are per-method).
Rewriting tools work outside those invariants all the time. The natural question "is the local that this expression reads assigned anywhere in the method?" is asked over a whole method body, and with name equality the answer is wrong whenever another block declares the same name:
if (ref != null) {
Map<String, Fingerprint> m = ref.get();
if (m != null)
return m;
}
Map<String, Fingerprint> m = new TreeMap<>();
for (Map.Entry<String, String> r : record.entrySet()) {
m.put(r.getKey(), r.getValue()); // reads the second m, never assigned after its declaration
}
Collecting Assignment.variableTarget() over the body and testing assigned.contains(ve.variable()) reports the read of the second m as a read of an assigned local (the first m has an assignment-like initializer elsewhere in some variants of this shape, and any m = … anywhere taints both). The same conflation reaches Set<Variable> of locals declared inside a block, "is this element variable assigned", and name-based taken sets — three finders in one tool had to be rewritten around it.
Proposal
Give a LocalVariable an identity for its declaration, without changing equals:
LocalVariable.declaration()(ordeclarationId()): theLocalVariableCreation/ForEachStatementinitializer /TryStatement.CatchClause/ pattern that declares it, or a stable per-method index assigned by the parser, as the anonymous-type index is; two reads of one declaration share it, two declarations of one name do not.- Alternatively a
Variable.scopeQualifiedName()that includes the declaring statement's index path, so that a caller that needs scope-aware equality can key on that instead.
The assignmentExpression() already on the interface is a per-declaration fact that the reads carry around; the declaration identity is the same kind of fact and would retire the caller-side scope walk below.
Workaround used
A Visitor over the method body that keeps a stack of scopes (beforeStatement pushes, afterStatement pops; a LocalVariableCreation declares into the enclosing scope, a for-each or for initializer and a catch variable into the statement's scope), resolves each VariableExpression to the declaring element by identity, and falls back to name equality for what it cannot place (parameters, lambda parameters, pattern variables).
Seen on 0.9.5-alpha.13; the note in LocalVariableImpl is unchanged on devel.
- 主要言語
- Java
- スター
- 1
- フォーク
- 1
- 平均マージ
- 1時間 58分
- マージ済み PR(30日)
- 5
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
CodeLaser/maddi のほかの issue
-
build/ci good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
bug front-end:javac
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
-
C# printer: an inner class of a generic class needs the outer type's arguments (Outer<A>.Inner)オープンfront-end:csharp
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 10/100
-
Java → C# translation: an idiomatic C# printer driven by the modification and nullability analysesオープンenhancement extension front-end:csharp
難易度 5/5 1週間以上 初心者へのやさしさ 8/100
CodeLaser/maddi の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
apache/rocketmq-dashboard#6896 ·
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
OpenIntegrationEngine/engine#496 ·
メンテナーはふだん 1 日以内に返信
-
enhancement good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
SasanLabs/VulnerableApp#836 ·
メンテナーはふだん 1 日以内に返信