Alias arguments are substituted one at a time: Below(b, a) is expanded as a < a, giving a false "can never be true" warning

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

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

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

研究方向

Read Expression.changeAlias and the unsatisfiability check in TypeChecker; the issue identifies the sequential substitute call and provides a minimal Java reproducer. Check how PR #489 performs simultaneous substitution for the where lines, then verify that the reproducer no longer warns while run() passes and run2() is rejected.

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

描述

bug

Impact: an alias whose arguments reuse its own parameter names in a different order is expanded wrongly, because the arguments are substituted one at a time. At the declaration this gives a false "This refinement can never be true" warning. Call sites look right in this repro, because their arguments are renamed to fresh variables before the alias is expanded. Any other path that expands an alias over unrenamed names would check the wrong formula.

Minimal reproducer

import liquidjava.specification.Refinement;
import liquidjava.specification.RefinementAlias;

@RefinementAlias("Below(int a, int b) { a < b }")
public class Probe {
    static void need(int a, int b, @Refinement("Below(b, a)") int unused) {}

    static void run() {
        need(5, 3, 0); // Below(3, 5) = 3 < 5: holds
    }

    static void run2() {
        need(3, 5, 0); // Below(5, 3) = 5 < 3: must be rejected
    }
}

Actual (main @ cd49fea3):

Warning: This refinement can never be true
6 |     static void need(int a, int b, @Refinement("Below(b, a)") int unused) {}
  |                                                 ^^^^^^^^^^^
Refinement Error: b == 5 && a == 3 is not a subtype of Below(b, a)      (line 13, correct)

run() passes and run2() is rejected, both correct. The warning is wrong: b < a is satisfiable.

Cause. Expression.changeAlias builds the expansion with sub = sub.substitute(varExp, aliasExp) for each parameter in turn. For Below(b, a) with parameters (a, b): a < b becomes b < b after a := b, then a < a after b := a. The unsatisfiability check in TypeChecker expands the declared refinement with the parameters' own names, so it checks a < a.

Expected: substitute all arguments at once, i.e. a simultaneous substitution, or rename the alias parameters to fresh names first. Then the declaration gets no warning.

Found while working on #295 (PR #489 builds its expansions with a simultaneous substitution for the where lines, but does not change changeAlias).

主要語言
Java
星號
73
分支
38
平均合併
12 小時 32 分鐘
30 天內合併 PR
45

環境準備

從這裡開始

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

liquid-java/liquidjava 的其他 Issue

查看 liquid-java/liquidjava 的全部 Issue

相似的 Issue

更多 Java Issue

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

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