String index comparison emits char vs string literal: not comparable

オープン
#262 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
58/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
typescript
領域
compilers, tooling

調査の方向性

Start by locating the Dafny backend code that lowers string indexing and emits string literals; the issue does not name those files. Reproduce with the included firstIsA example using lsc check --backend=dafny and inspect the generated Dafny and resolver error. Done when the indexed character comparison resolves successfully and the example verifies.

索引モデルが issue の本文から書いたものです。

説明

Summary

String element access lowers to a Dafny char, but a compared string literal stays a string, so any indexed character comparison fails resolution:

//@ backend dafny
export function firstIsA(s: string): boolean {
//@ verify
//@ ensures \result === (s.length > 0 && s[0] === "a")
  return s.length > 0 && s[0] === "a";
}

Evidence

  • Before: lsc check --backend=dafny generates, then Dafny reports a.verify.dfy(9,46): Error: arguments must have comparable types (got char and string) for (s[0] == "a"). Exit 1, no workaround that keeps indexing (slice comparisons are the only way through).
  • After (expected): the literal is emitted as a Dafny char ('a') or the index access is modeled as a single-character string. Related: #192 (string literal emission in switch cases).

Merge Danger

Door: two-way — generation succeeds, failure surfaces at Dafny resolution, never as a silent wrong proof.

Blast radius: toolchain — any s[i] === "..." comparison in an annotated function.

主要言語
TypeScript
スター
113
フォーク
13
平均マージ
16時間 22分
マージ済み PR(30日)
40

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

midspiral/LemmaScript のほかの issue

midspiral/LemmaScript の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。