Dafny: string-literal unions like `'==' | '!='` map to the same constructor name and the file is rejected
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 67/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- typescript
- 領域
- compilers
調査の方向性
The issue points to tools/src/dafny-emit.ts, specifically dafnyCtorName around line 1756. Read its current name mapping and the nearby tests for Dafny string-literal unions, then reproduce the collision with the provided '==' | '!=' example. Done when distinct literals produce distinct valid Dafny constructors, or lsc reports the conflicting source literals clearly, and the regression is covered by a test.
索引モデルが issue の本文から書いたものです。
説明
Version: lsc 0.6.10 (npm), Dafny 4.11. Still present on main at 93283ec, tools/src/dafny-emit.ts, dafnyCtorName (around line 1756).
A string-literal union becomes a datatype whose constructor names are the literals, with every character outside [A-Za-z0-9_'?] mapped to _. Different literals can map to the same name:
//@ backend dafny
export type Op = '==' | '!='
export function negate(op: Op): Op {
//@ verify
//@ ensures \result !== op
return op === '==' ? '!=' : '=='
}
datatype Op = i__ | i__
function negate(op: Op): Op
{
if op.i__? then Op.i__ else Op.i__
}
i8.dfy(3,20): Error: Duplicate datatype constructor name: i__
The same happens with 'a-b' | 'a_b' | 'a.b', which gives datatype K = a_b | a_b | a_b. The comment on dafnyCtorName says a collision "fails loudly in Dafny rather than silently merging", so this isn't unsound. But operator tokens ('==', '<=', '+'), MIME types and dotted or dashed keys are common in literal unions. Valid TypeScript can't be verified, and the error points at generated names.
In TypeScript, '==' and '!=' are different types and values.
Suggested fix: make the mapping injective. Two options:
- Encode each non-identifier character, e.g.
_x3D_x3Dfor==and_x21_x3Dfor!=, so different literals always give different names. - Keep the readable form and add a numeric suffix on collision (
i__,i___2).
If neither fits, lsc could detect the collision itself and report the two source literals.
Workaround: use identifier-shaped literals in verified code ('eq' | 'ne'), and map them to the operator text outside it. With 'eq' | 'ne', the function above verifies.
- 主要言語
- TypeScript
- スター
- 113
- フォーク
- 13
- 平均マージ
- 16時間 22分
- マージ済み PR(30日)
- 40
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
midspiral/LemmaScript のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
midspiral/LemmaScript#308 ·
メンテナーはふだん 1 日以内に返信
-
Dafny: `toUpperCase`/`toLowerCase` are modeled as ASCII-only, so false contracts about non-ASCII text verify対応中かも @quangng2000 が 1 日前に担当しました。 オープン
midspiral/LemmaScript#312 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 1〜2日 初心者へのやさしさ 56/100
midspiral/LemmaScript#311 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 48/100
midspiral/LemmaScript#310 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 43/100
midspiral/LemmaScript#307 ·
メンテナーはふだん 1 日以内に返信
midspiral/LemmaScript の issue をすべて見る
似ている issue
-
area: batch
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
inabagumi/shinju-date#7294 ·
メンテナーはふだん 1 日以内に返信
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
streaming-video-technology-alliance/common-media-library#700 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
vercel-labs/ui#809 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
KrisCris/village-in-the-shade-guide#75 ·
メンテナーはふだん 1 日以内に返信
-
bot:ai-assisted component:platform-js status:untriaged
難易度 1/5 1時間未満 初心者へのやさしさ 74/100
midnightntwrk/platform-js#38 ·