`store.users.push(x)` in a handler compiles with no diagnostic, and the write is lost

Ouverte
#97 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
62/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
javascript, typescript
Domaine
compilers

Piste de recherche

Start by running analyze on the program in the issue, which reports nothing, and by reading the lowered handler __rt.snapshot(v$store)?.users?.push(2). Find where the checker walks handler bodies and inspect member calls whose receiver is a source path, then check the list of mutating methods against decision 20 in 07. Done when analyze emits a diagnostic that points to the := form for push and the other listed methods, and the existing checker tests still pass.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Calling a mutating method on a source's value in a handler, such as store.users.push(2), compiles with no diagnostic, and the write never happens. 07 decision 20 says "only := and guess mutate", so this should be a diagnostic that points to the := form, for example store.users := [...store.users, 2].

Program

export default component App() {
  source store := { users: [1] }
  <main>
    <button onClick={() => { store.users.push(2) }}>add</button>
    <p>{len(store.users)}</p>
  </main>
}

analyze reports no diagnostics. The handler lowers to:

__rt.snapshot(v$store)?.users?.push(2);

That calls push on a read of the store, outside its setter. Solid ignores the write. In development it logs [STORE_WRITE_OUTSIDE_SETTER] Writing store property "1" outside its setter was ignored; that warning is development-only, so a production build drops the write without a word.

Frames

instant action frame
0 mount add1
1 click add add1 (the list is unchanged)

splice behaves the same way, and so presumably do the other mutating methods (pop, shift, unshift, sort, reverse, fill, copyWithin, and Map/Set writes). A program can also reach this through a plain function the handler calls with the source's value, which the checker may not be able to see. The direct call on a source path is the case it can see.

Version: main at e650b85.

Langage dominant
TypeScript
Étoiles
127
Forks
7
Merge moyen
15 h 42 min
PR mergées (30 j)
63

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de solidjs/reactivescript

Toutes les issues de solidjs/reactivescript

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.