optional-read
Ce que cela signifie#
A body reads an optional field (position: optional float32) as if it were always there: absent, it would be a silent zero. Read it with if let p = msg.position { … } (the arm runs when it is there, p its value), guard let p = msg.position else { return } (p from there on) or msg.position ?? 0.0 (its value, else the default). The quick fix writes ?? <zero of the type>; it is offered in the editor, archec fix leaves it, as the default is yours to choose. Setting the field (msg.position = 1.5) needs none. An error from edition 1.1; before it (and with no edition) a warning, and the body reads the field as it is.
Comment le corriger#
Le message dit ce qui ne va pas et où, et souvent ce qui était voulu (Did you mean …?). Modifiez le modèle pour que ce que décrit cette page ne soit plus vrai, puis vérifiez à nouveau : archec check main.arche.
Une erreur : archec ne construit rien tant qu’elle n’est pas corrigée.
archec check --beginner reformule les messages les plus courants en mots simples, avec les noms qui existent.
La correction automatique#
archec n’a pas de correction propre à ce code. Quand le message dit Did you mean …?, VS Code propose ce changement (Quick Fix).
Dans le terminal#
archec explain optional-read affiche cette explication ; archec explain behaviour liste les codes de son domaine.