Soundness: a local variable with a constant's name shadows the constant (Format.JPG read as local JPG)
維護者通常 2 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
從 issue 中確定的 RefinementTypeChecker.visitCtFieldRead 開始,使用提供的 Java 範例重現名稱衝突。檢查內容查找如何區分區域變數和正在讀取的欄位;issue 描述了一個候選修正,並報告全部 347 個測試都通過。完成的標誌是重現程式在 onlyPng(g) 處回報 refinement 錯誤,且測試套件仍然通過。
由索引模型根據 Issue 內容生成。
描述
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.
- 主要語言
- Java
- 星號
- 67
- 分支
- 36
- 平均合併
- 3 天 16 小時
- 30 天內合併 PR
- 9
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
liquid-java/liquidjava 的其他 Issue
-
Soundness: short-circuit RHS assignments are treated as executed可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 4/5 3-5 天 新手友好度 68/100
liquid-java/liquidjava#323 ·
維護者通常 2 天內回覆
-
bug
難度 3/5 1-2 天 新手友好度 76/100
liquid-java/liquidjava#322 ·
維護者通常 2 天內回覆
-
Fields with the same name in different classes collide可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉bug
難度 4/5 3-5 天 新手友好度 52/100
liquid-java/liquidjava#318 ·
維護者通常 2 天內回覆
-
Nested classes wipe the outer class's field refinements可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉bug
難度 4/5 3-5 天 新手友好度 55/100
liquid-java/liquidjava#317 ·
維護者通常 2 天內回覆
-
Reading a field of a class declared later in the file loses its refinement可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉bug
難度 4/5 3-5 天 新手友好度 62/100
liquid-java/liquidjava#316 ·
維護者通常 2 天內回覆
查看 liquid-java/liquidjava 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
-
area/docs
難度 1/5 1 小時以內 新手友好度 88/100
維護者通常 1 天內回覆
-
BoxChart rejects valid List.of data with NullPointerException可能已有人在做 @PHJ2000 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 76/100