Soundness: a local variable with a constant's name shadows the constant (Format.JPG read as local JPG)
Maintainer antworten meist innerhalb von 2 Tagen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 78/100
Rechercherichtung
Beginne in RefinementTypeChecker.visitCtFieldRead, das im Issue angegeben ist, und reproduziere den Namenskonflikt mit dem bereitgestellten Java-Beispiel. Prüfe, wie die Kontextsuche zwischen einer lokalen Variable und dem gelesenen Feld unterscheidet; das Issue beschreibt einen möglichen Fix und berichtet, dass alle 347 Tests bestehen. Erledigt ist es, wenn der Reproducer einen Refinement-Fehler bei onlyPng(g) meldet und die Testsuite weiterhin besteht.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Description
A field read of a constant such as Format.JPG is resolved to a local variable with the same simple name (JPG), if one is in scope, instead of the constant. The refinement of the local is then used, so real violations are accepted.
Minimal reproducer
import liquidjava.specification.Refinement;
public class Repro {
enum Format { JPG, PNG }
static void onlyPng(@Refinement("_ == Format.PNG") Format f) {}
public static void main(String[] args) {
Format JPG = Format.PNG; // a local that happens to share the constant's name
Format g = Format.JPG; // the enum constant JPG, not the local
onlyPng(g); // expected error: g is JPG
}
}
Expected
A refinement error at onlyPng(g): g holds Format.JPG.
Actual
Correct! Passed Verification.
Removing the line Format JPG = Format.PNG; gives the expected error (g == JPG is not a subtype of g == Format.PNG), so the name clash is what hides it.
Reproduced on main at fbfb4e23.
Where
RefinementTypeChecker.visitCtFieldRead: its first branch looks the field up by simple name in the context (where the local lives) without checking that the variable found is the field being read. A candidate fix (about 5 lines, found during the review of #319) only uses the context variable when it really is that field, and otherwise falls through; it keeps all 347 tests passing.
Context
Found by the adversarial review of #319 (fix for #302): with #319 the same clash inside an if condition (if (f == Format.JPG)) turns a former crash into an accepted violation, so this should be fixed before or with #319.
- Vorherrschende Sprache
- Java
- Sterne
- 67
- Forks
- 36
- Ø Merge
- 3 T. 16 Std.
- Gemergte PRs (30 T.)
- 9
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus liquid-java/liquidjava
-
Soundness: short-circuit RHS assignments are treated as executedEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 68/100
liquid-java/liquidjava#323 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Soundness: a field of another class or object is read as this class's field with the same nameOffenbug
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 76/100
liquid-java/liquidjava#322 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Fields with the same name in different classes collideEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offenbug
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 52/100
liquid-java/liquidjava#318 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Nested classes wipe the outer class's field refinementsEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offenbug
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 55/100
liquid-java/liquidjava#317 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Reading a field of a class declared later in the file loses its refinementEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offenbug
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 62/100
liquid-java/liquidjava#316 ·
Maintainer antworten meist innerhalb von 2 Tagen
Alle Issues in liquid-java/liquidjava
Ähnliche Issues
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
apache/skywalking#14120 ·
Maintainer antworten meist innerhalb von 1 Tag
-
[Feature] 关于启动游戏进度条显示的优化Offenenhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
HMCL-dev/HMCL#6943 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
micronaut-projects/micronaut-core#13677 ·
Maintainer antworten meist innerhalb von 1 Tag
-
new feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
apache/rocketmq-dashboard#5594 ·
Maintainer antworten meist innerhalb von 3 Tagen