A presence check in a `while` condition does not narrow the rest of the condition or the loop body
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 22/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- typescript
- Lĩnh vực
- compilers
Hướng nghiên cứu
This is compiler work in the narrowing pass: start from the "Narrow Rules" section of TOOLS.md, then find where the existing if-condition presence-check narrowing is implemented and why the while condition never reaches it. Run lsc gen on the reproduction in the issue and diff the emitted Dafny to see that i stays an Option in the condition and body. Acceptance is Dafny output that verifies plus a regression test covering both a body that reads the narrowed value and one that reassigns the variable; note that PR #346 already targets this, so coordinate before starting.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Problem
TypeScript narrows an optional inside a while loop guarded by a presence check: in while (i !== undefined && i < a.length) { … a[i] … }, i is a number in the rest of the condition and in the body. lsc narrows the same check in an if condition, but not in a while condition. TOOLS.md ("Narrow Rules") has no rule for while conditions. lsc gen exits 0, and the emitted loop compares and indexes with the Option. Dafny rejects the output, so no false proof results.
Reproduced on upstream main at add6ccd (0.6.10).
Reproduction
export function whileIdx(a: number[], i?: number): number {
let s = 0;
while (i !== undefined && i >= 0 && i < a.length) {
s = a[i];
i = undefined;
}
return s;
}
emits:
method whileIdx(a: seq<int>, i: Option<int>) returns (res: int)
{
var i := i;
var s := 0;
while (((match i { case Some(i_) => true case None => false }) && (i >= 0)) && (i < |a|))
{
s := a[i];
i := None;
}
return s;
}
dafny verify reports four errors: arguments to >= must be of a numeric type, bitvector type, ORDINAL, char, or a set-like type (instead got Option<int> and int) and arguments to >= must have a common supertype (got Option<int> and int) for i >= 0, arguments to rank comparison must be datatypes (got Option<int> and int) for i < |a|, and incorrect type for selection into seq<int> (got Option<int>) for a[i].
Expected
A presence check at the start of a while condition narrows the rest of the condition and the loop body. The body can reassign the variable, as this one does, so the narrowing has to be re-established on every iteration rather than once before the loop. A match around the loop would not do that. One shape that does is to test and read the payload in the condition and body, for example while (i.Some? && i.value >= 0 && i.value < |a|) { s := a[i.value]; i := None; }, with each read in the body unwrapping i only where TypeScript still treats i as defined.
If while narrowing stays unsupported, lsc should report it at the source position rather than emit Dafny that does not type-check.
Acceptance criteria
- The reproduction generates Dafny that verifies.
- A regression test covers a
whilepresence check whose body reads the narrowed value and a body that reassigns the variable.
- Ngôn ngữ chính
- TypeScript
- Star
- 113
- Fork
- 13
- Merge trung bình
- 15 giờ 35 phút
- Pull request đã merge (30 ngày)
- 56
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của midspiral/LemmaScript
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
midspiral/LemmaScript#355 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
In a pure function body, a `const` declared inside an `if` branch stays in scope after the `if`, so a false `ensures` can verifyCó thể đã có người làm @namin đã nhận hôm nay. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
midspiral/LemmaScript#362 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
A `const` or `let` inside a bare `{ }` block stays in scope after the block, so a false `ensures` can verifyCó thể đã có người làm @namin đã nhận hôm nay. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 15/100
midspiral/LemmaScript#361 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
A closure declared before a same-name `const` or `let` in its block reads the outer variable, so a false `ensures` can verifyCó thể đã có người làm @namin đã nhận hôm nay. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 18/100
midspiral/LemmaScript#360 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
An assignment used as an expression, such as `(x = 7);` or `const y = (x = 7)`, is extracted as an equality test, so a false `ensures` can verifyCó thể đã có người làm @namin đã nhận hôm nay. Đang mở
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 30/100
midspiral/LemmaScript#356 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của midspiral/LemmaScript
Issue tương tự
-
bug done
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
neavo/LinguaGacha#1124 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[fullsend] E2E: backstage-microsoft-auth — catalogQuery missing error handler for network errorsCó thể đã có người làm @fullsend-ai-coder đã nhận hôm nay. Đang mởe2e-failure ready-to-code
Độ khó 2/5 Dưới một giờ Mức phù hợp với người mới 78/100
redhat-developer/rhdh-plugin-export-overlays#4821 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
brylie/mission-island#225 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement from-app needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
nightly-labs/openbot#14986 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
status/need-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
google-gemini/gemini-cli#30412 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày