Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Soundness: a field of another class or object is read as this class's field with the same name

未關閉
#322 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 2 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
76/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
java
領域
compilers

研究方向

Start at OperationsChecker.getOperationRefinements and RefinementTypeChecker.visitCtFieldRead, using the supplied Limits/Repro example as the first reproducer. Trace how CtFieldRead targets are resolved for class fields, object fields, and enum constants, then verify that the reproducer reports a refinement error and that the name-clash cases no longer use the current class's field refinement.

由索引模型根據 Issue 內容生成。

描述

bug

Description

Reading a field of another class or object (Limits.max, other.val) resolves to the current class's own field with the same name (this.max) when the current class has one. The wrong refinement is used, so real violations are accepted.

Minimal reproducer

import liquidjava.specification.Refinement;

class Limits {
    static final int max = 10;
}

public class Repro {
    int max = 5;                       // this class also has a field named max

    void check() {
        @Refinement("_ == 5") int k = Limits.max;   // expected error: Limits.max is 10
    }
}

Expected

A refinement error: Limits.max is 10, not 5.

Actual

Correct! Passed Verification.

Removing the field int max = 5; from Repro gives the expected error (k == 10 is not a subtype of k == 5), so the name clash is what hides it.

Reproduced on main at fbfb4e23.

Where

OperationsChecker.getOperationRefinements / RefinementTypeChecker.visitCtFieldRead: a CtFieldRead is named with Formats.THIS (this#<name>) regardless of its target, so any field read whose simple name matches a field of the current class picks up that field's refinement. The same shape affects enum constants (Format.JPG read as this.JPG when the class has a field JPG) and fields of other objects (other.val read as this.val).

Context

Found by the adversarial review of #319 (fix for #302). Pre-existing on main, independent of #319.

主要語言
Java
星號
67
分支
36
平均合併
3 天 16 小時
30 天內合併 PR
9

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

liquid-java/liquidjava 的其他 Issue

查看 liquid-java/liquidjava 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。