LocalVariable: no identity for the declaration, so same-named locals in sibling scopes are one variable
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 28/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Java
- Stelle
- 1
- Fork
- 1
- Merge medio
- 2h 22m
- PR unite (30g)
- 4
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di CodeLaser/maddi
-
build/ci good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
C# printer: an inner class of a generic class needs the outer type's arguments (Outer<A>.Inner)Apertafront-end:csharp
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 10/100
-
Java → C# translation: an idiomatic C# printer driven by the modification and nullability analysesApertaenhancement extension front-end:csharp
Difficoltà 5/5 Più di una settimana Idoneità per principianti 8/100
-
enhancement extension front-end:csharp
Difficoltà 5/5 Più di una settimana Idoneità per principianti 8/100
Tutte le issue di CodeLaser/maddi
Issue simili
-
Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
MinecraftForge/MinecraftForge#10902 · 1 commento ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
refinedmods/refinedstorage2#1421 ·
-
StepExamBenchmarkTest runs a loop and prints a timing but asserts nothingForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertajules
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
open-learning-exchange/myplanet#18199 · 1 commento ·
I maintainer di solito rispondono entro 4 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
Scheme-less stream URLs throw NullPointerException instead of URISyntaxExceptionForse già presa @blihio l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
pedroSG94/RootEncoder#2218 ·
I maintainer di solito rispondono entro 3 giorni