Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Soundness: a local variable with a constant's name shadows the constant (Format.JPG read as local JPG)

未关闭 适合新手
#321 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java
领域
testing

调研方向

从 issue 中确定的 RefinementTypeChecker.visitCtFieldRead 开始,使用提供的 Java 示例复现名称冲突。检查上下文查找如何区分局部变量和正在读取的字段;issue 描述了一个候选修复,并报告全部 347 个测试均通过。完成的标志是复现程序在 onlyPng(g) 处报告 refinement 错误,并且测试套件仍然通过。

由索引模型根据 Issue 内容生成。

描述

bug

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
平均合并
4 天 17 小时
30 天内合并 PR
7

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

liquid-java/liquidjava 的其他 Issue

查看 liquid-java/liquidjava 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。