`null` and `undefined` both become `None`, so a false ensures proves for `T | null | undefined`
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- typescript
調査の方向性
Start by reading the TypeScript-to-Dafny translation for union types and strict equality, using the lsc check --backend=dafny examples in the issue to reproduce both failures. The issue names no source files or tests, so locate the relevant translation code and its tests before changing anything. Done means strict checks distinguish null from undefined for T | null | undefined, and the shown incorrect proof and payload comparison are handled soundly.
索引モデルが issue の本文から書いたものです。
説明
Version: lsc 0.6.10 (npm), Dafny 4.11.
A type string | null | undefined is modelled as Option<string>, and both x === null and x === undefined become x == None. The model can't tell them apart. A contract that tells them apart proves things that are false in JavaScript.
//@ backend dafny
export function label(x: string | null | undefined): string {
//@ verify
//@ ensures x === null ==> \result === "unset"
return x === undefined ? "unset" : "set"
}
lsc check --backend=dafny i2.ts emits the following and verifies it (1 verified, 0 errors):
function label_(x: Option<string>): string
{
match x {
case Some(i_x_val) => "set"
case None => "unset"
}
}
lemma label_ensures(x: Option<string>)
ensures ((match x { case Some(i_) => false case None => true }) ==> (label_(x) == "unset"))
In JavaScript, label(null) is "set", so the proven ensures is false.
A body that tests for both values doesn't resolve. After the first test narrows x to Some, the second is emitted against the payload:
//@ backend dafny
export function kind(x: string | null | undefined): number {
//@ verify
return x === null ? 1 : x === undefined ? 2 : 3
}
match x {
case Some(i_x_val) =>
if (i_x_val == None) then 2 else 3
case None => 1
}
i2b.dfy(9,18): Error: arguments must have comparable types (got string and Option<?>)
In JavaScript, null === undefined is false. Only loose == treats them as the same.
Suggested direction: when a type holds both null and undefined, either reject it with a message, or model the two as different values (for example a three-constructor datatype or Option<Option<T>>). A strict === null and a strict === undefined would then be different tests. Folding the two is sound only when the type holds just one of them, or when every test is loose (== null).
Workaround: in verified code, use T | undefined or T | null, not both. Convert at the boundary, e.g. x ?? undefined.
- 主要言語
- TypeScript
- スター
- 113
- フォーク
- 13
- 平均マージ
- 15時間 35分
- マージ済み PR(30日)
- 56
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
midspiral/LemmaScript のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
midspiral/LemmaScript#355 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
In a pure function body, a `const` declared inside an `if` branch stays in scope after the `if`, so a false `ensures` can verify対応中かも @namin が今日担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
midspiral/LemmaScript#362 ·
メンテナーはふだん 1 日以内に返信
-
A `const` or `let` inside a bare `{ }` block stays in scope after the block, so a false `ensures` can verify対応中かも @namin が今日担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 15/100
midspiral/LemmaScript#361 ·
メンテナーはふだん 1 日以内に返信
-
A closure declared before a same-name `const` or `let` in its block reads the outer variable, so a false `ensures` can verify対応中かも @namin が今日担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 18/100
midspiral/LemmaScript#360 ·
メンテナーはふだん 1 日以内に返信
-
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 verify対応中かも @namin が今日担当しました。 オープン
難易度 3/5 半日 初心者へのやさしさ 30/100
midspiral/LemmaScript#356 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
midspiral/LemmaScript の issue をすべて見る
似ている issue
-
bug done
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
neavo/LinguaGacha#1124 ·
メンテナーはふだん 1 日以内に返信
-
[fullsend] E2E: backstage-microsoft-auth — catalogQuery missing error handler for network errors対応中かも @fullsend-ai-coder が今日担当しました。 オープンe2e-failure ready-to-code
難易度 2/5 1時間未満 初心者へのやさしさ 78/100
redhat-developer/rhdh-plugin-export-overlays#4821 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
brylie/mission-island#225 ·
メンテナーはふだん 1 日以内に返信
-
status/need-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
google-gemini/gemini-cli#30412 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信