Dafny: `toUpperCase`/`toLowerCase` are modeled as ASCII-only, so false contracts about non-ASCII text verify
I maintainer di solito rispondono entro 1 giorno
@quangng2000 ci sta già lavorando.
Dal 16/11/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
lsc 0.6.10, Dafny 4.11.0, under both unicode-scalar (the default) and javascript-utf16.
Repro
//@ backend dafny
export function upperKeepsLength(s: string): boolean {
//@ verify
//@ ensures \result === true
return s.toUpperCase().length === s.length;
}
export function lowerOfNonAsciiIsItself(s: string): boolean {
//@ verify
//@ requires s === "Ä"
//@ ensures \result === true
return s.toLowerCase() === s;
}
lsc check --backend=dafny reports 5 verified, 0 errors for this file, both as it is and with
//@ option string-semantics javascript-utf16 + //@ option dafny-library local.
JavaScript disagrees with both contracts:
upperKeepsLength("ß") // false: "ß".toUpperCase() is "SS"
lowerOfNonAsciiIsItself("Ä") // false: "Ä".toLowerCase() is "ä"
"İ".toLowerCase().length // 2 (a combining dot is added)
Cause
The emitted helpers map only A-Z / a-z and promise to keep the length:
function StringToUpper(s: string): string
ensures |StringToUpper(s)| == |s|
{
...
var upper := if 'a' <= c <= 'z' then (c - 'a' + 'A') as char else c;
...
}
String.prototype.toUpperCase/toLowerCase apply the full Unicode case mapping (UnicodeData plus
SpecialCasing). That mapping changes non-ASCII letters and can change the length. So a proof that uses
these helpers is only valid for ASCII input, but nothing in the proof requires the input to be ASCII.
toLocaleUpperCase/toLocaleLowerCase likely have the same problem if they are lowered the same way.
Suggested fix
Any one of these would make it sound:
- Model the result as uninterpreted (an opaque function with no length or content guarantees), possibly
with lemmas that hold in JavaScript, e.g. ASCII input gives the ASCII result. - Keep the ASCII model but emit it with
requires forall i :: 0 <= i < |s| ==> s[i] < 128 as char, so a
caller has to prove the input is ASCII. - Reject the calls loudly, as is done for other unsupported built-ins.
Workaround
Fold explicitly over character codes (String.fromCharCode(c + 32) for 65 <= c <= 90). This is proven
and matches JavaScript on every code unit. Alternatively, keep the Unicode case mapping in sampled code
and prove only what comes after it.
- Lingua principale
- TypeScript
- Stelle
- 113
- Fork
- 13
- Merge medio
- 16h 8m
- PR unite (30g)
- 42
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di midspiral/LemmaScript
-
Difficoltà 4/5 1-2 giorni Idoneità per principianti 56/100
midspiral/LemmaScript#311 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 48/100
midspiral/LemmaScript#310 ·
I maintainer di solito rispondono entro 1 giorno
-
Dafny: string-literal unions like `'==' | '!='` map to the same constructor name and the file is rejectedForse già presa @DevChiniwala l’ha presa oggi. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 67/100
midspiral/LemmaScript#309 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 43/100
midspiral/LemmaScript#307 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 56/100
midspiral/LemmaScript#306 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di midspiral/LemmaScript
Issue simili
-
agent-ready area: ui-server priority: p3 type: test
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
schlessera/brain-kit#4249 ·
I maintainer di solito rispondono entro 1 giorno
-
documentation tool triaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
can1357/oh-my-pi#19608 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
dependencies tech-debt
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
bcgov/nr-waste-plus#1549 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
blixvip/solana-token-meta#17 ·
-
enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
blixvip/solana-tx-parse#18 ·