`ReadonlySet<T>` and `ReadonlyMap<K, V>` are not mapped to `set` / `map`
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 82/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- typescript
調査の方向性
tools/src/types.ts の tyFromTypeNode(199行目付近)から始め、issue が示唆するように、文字列ベースの型解析経路があるかどうかを確認してください。ReadonlyArray のマッピング方法を、既存の Set、Map、Record のケースと比較してください。ReadonlySet と ReadonlyMap のパラメーターが Dafny の set 型と map 型にマッピングされ、issue の例が正常に出力され検証されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Version: lsc 0.6.10 (npm), Dafny 4.11. Still present on main at 93283ec, tools/src/types.ts, tyFromTypeNode (around line 199).
ReadonlyArray<T> and readonly T[] become seq<T>. Set<T> becomes set<T>, and Map<K, V> and Record<K, V> become map<K, V>. ReadonlySet and ReadonlyMap fall through to a user type, so the usual read-only operations fail:
//@ backend dafny
export function known(names: ReadonlySet<string>, n: string): boolean {
//@ verify
//@ ensures \result === names.has(n)
return names.has(n)
}
ERROR: Dafny emission failed for 'known' in i7.ts: Unsupported Dafny method call: .has() on user
export function copy(s: ReadonlySet<string>): Set<string> {
//@ verify
return new Set(s)
}
ERROR: new Set(...) expects an array argument (got user)
export function lookup(m: ReadonlyMap<string, number>, k: string): number {
//@ verify
return m.get(k) ?? 0
}
ERROR: nullish reached transform — narrow should have rewritten it: {"kind":"nullish","left":{"kind":"call","fn":{"kind":"field","obj":{"kind":"var","name":"m","ty":{"kind":"user","name":"ReadonlyMap<string, number>"}}, ...
Reading only .size gets past emission. lsc then expands the lib interface into a datatype that does not parse:
type forEach(==)
type has(==)
...
datatype ReadonlySet = ReadonlySet(forEach: forEach, has: has, size: int, entries: entries, keys: keys, values: values, i__@iterator@9: i__)
function size(s: ReadonlySet<string>): int
i7d.dfy(15,123): Error: closeparen expected
i7d.dfy(15,134): Error: invalid TopDecl
ReadonlySet<T> is Set<T> without the mutators, and ReadonlyMap<K, V> is Map<K, V> without them. Verified code is pure, so it already can't call add / set / delete. These are the natural parameter types for it.
Suggested fix: in tyFromTypeNode, and in the string-based type path if there is one, treat ReadonlySet like Set and ReadonlyMap like Map, as ReadonlyArray is already treated like Array:
if ((name === "Set" || name === "ReadonlySet") && args.length === 1) return { kind: "set", ... };
if ((name === "Map" || name === "ReadonlyMap" || name === "Record") && args.length === 2) ...
Workaround: declare the parameter as Set<T> / Map<K, V>. With Set<string>, the known function above verifies, but callers that hold a ReadonlySet then need a cast.
- 主要言語
- TypeScript
- スター
- 113
- フォーク
- 13
- 平均マージ
- 16時間 22分
- マージ済み PR(30日)
- 40
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
midspiral/LemmaScript のほかの issue
-
Dafny: `toUpperCase`/`toLowerCase` are modeled as ASCII-only, so false contracts about non-ASCII text verify対応中かも @quangng2000 が今日担当しました。 オープン
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 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 67/100
midspiral/LemmaScript#309 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 43/100
midspiral/LemmaScript#307 ·
メンテナーはふだん 1 日以内に返信
midspiral/LemmaScript の issue をすべて見る
似ている issue
-
Type/Improvement
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
OpenNSW/nsw-srilanka#1259 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
oxc-project/tsrs#1010 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Fission-AI/OpenSpec#2260 ·
メンテナーはふだん 1 日以内に返信
-
Add: ESP 1 UKオープンcheck:passed streams:add
難易度 1/5 1〜3時間 初心者へのやさしさ 64/100
メンテナーはふだん 1 日以内に返信
-
area:infra area:storage bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
THU-MAIC/OpenMAIC#2311 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信