[P2] Interpreter: qualified globalThis.isNaN keeps strict Number.isNaN semantics for coercible arguments

Chiusa Adatta ai principianti
#2,905 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@nickna ci sta già lavorando.

Dal 27/10/2026.

  • #2907 di @Nitjsefnie — aperta
  • #3040 di @nickna — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
75/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
csharp, typescript
Ambito
backend, compilers

Direzione di ricerca

Leggi il ramo name == "isNaN" in src/SharpTS/Runtime/Types/SharpTSGlobalThis.cs e la registrazione di isNaN in src/SharpTS/Runtime/BuiltIns/NumberBuiltIns.cs, quindi confrontali con il gestore globale di isNaN. Riproduci i casi segnalati usando l’interprete verificato; il lavoro è terminato quando sia isNaN sia globalThis.isNaN restituiscono true per undefined e per le stringhe non numeriche.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

In the checked interpreter, globalThis.isNaN(x) and bare isNaN(x) are not the same function for arguments that need numeric coercion. The qualified read resolves through the Number namespace static (src/SharpTS/Runtime/Types/SharpTSGlobalThis.cs, the name == "isNaN" branch returning GetStaticMethod("Number", name)), and that static requires args[0].Kind == ValueKind.Number before testing for NaN (src/SharpTS/Runtime/BuiltIns/NumberBuiltIns.cs, the .MethodV2("isNaN", ...) registration). It therefore answers false for every non-number, including coercible ones, while the bare global handler coerces.

For undefined and non-numeric strings the two readings disagree: bare isNaN(undefined) is true (also per #2695's interpreter output) while globalThis.isNaN(undefined) is false. Node gives true for both forms.

Measured reference (node v24.17.0, plain JS semantics):

> console.log(isNaN(undefined), globalThis.isNaN(undefined), isNaN("abc"), globalThis.isNaN("abc"))
true true true true

The interpreter's qualified result follows from the cited code path on main (99b51889); I could not execute the interpreter locally to capture its literal output for these arguments.

Expected Behavior

isNaN and globalThis.isNaN are the same function. ToNumber(undefined) is NaN and ToNumber("abc") is NaN, so both forms print true, matching Node.

Reproduction Steps
  1. Run the following through the checked interpreter:
console.log(isNaN(undefined as any), globalThis.isNaN(undefined as any));
console.log(isNaN("abc" as any), globalThis.isNaN("abc" as any));
  1. Expected per Node: true true / true true. Current interpreter behavior: bare true, qualified false (source-derived from the cited fallback; the qualified globalThis.isNaN(null) → false line in #2695's output is consistent with, but could not distinguish, the strict reading since both readings agree on null).
Discovered During

Work on #2695 (bare global isNaN numeric coercion). Fixing the bare handler makes the bare/qualified divergence observable on coercible arguments. The qualified fallback is unchanged code on main; the divergence predates that fix.

Suggested Fix (unverified hypothesis)

Route the qualified isNaN read in src/SharpTS/Runtime/Types/SharpTSGlobalThis.cs to the same global handler the bare call uses, so both forms share the coercive path. parseInt/parseFloat/isFinite in the same branch may deserve the same check.

Lingua principale
C#
Stelle
156
Fork
4
Merge medio
13h 33m
PR unite (30g)
45

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nickna/SharpTS

Tutte le issue di nickna/SharpTS

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.