Artifact 37a21f921e3386036a7b5b9880b4c7ee394633356478c32f468ae9149f66cbe9:
- File typeparse/tests_tclsh/t67_conversion_variantes.out — part of check-in [582865c204] at 2026-10-23 11:20:46 on branch tip-764_tcl90 — Conversion rules between variants are now in place: this is version v15n, found in typeparse.zip. tcl type def temp {{double}celsius, {double}fahrenheit} type convert temp.celsius temp.fahrenheit {{x} {expr {$x*9/5.0 + 32}}} set {temp}t {celsius}100 set t(fahrenheit) ;# 212.0 set u {temp.fahrenheit}$t ;# 212.0, of type temp.fahrenheit type cast temp.fahrenheit $t ;# same Reading an inactive variant, or casting to {S.b}: If a rule exists, it is applied—even between variants with different underlying forms. For variants with the same form but no defined rule, an error occurs: "the current variant of temp is 'celsius', not 'fahrenheit'; both have the same form, so reading one as the other needs a rule: type convert temp.celsius temp.fahrenheit {{x} ...}." Otherwise, it defaults to a standard cast, as in v15k: reading {i}5 via $v(s) yields 5. This resolves the question left open in v15k regarding the reading of an inactive variant. Limitations, as previously agreed: Rules do not apply during type inference (e.g., `set {temp}y 5` remains ambiguous), nor during assignment (e.g., `set t {fahrenheit}50` changes the variant without performing a conversion). Rules cannot be chained, and each direction must be explicitly declared. `type convert` will reject cases involving two different sum types, an unknown variant, the same variant specified twice, or a mix of a variant and a simple (non-sum) type. For a sum type with a selector S($field), converted reads work, but the selector field itself cannot be modified via this mechanism. Two fixes included: Previously, `{temp.fahrenheit}$t` would ignore the requested variant and leave the value as `temp.celsius`. `type cast S.v` … previously resulted in an "unknown type 'v'" error. Both now work. Tests against v15: No new discrepancies; all expected `.out` outputs pass. Valgrind reports no issues with the new test cases. New test: `t67_conversion_variantes`. I have documented everything in `doc/ANNOTATIONS.fr.md` (section 8 and the path table) and in `noyau/LISEZMOI.md` (v15n). In the project plan, I have marked this item as complete, alongside the note regarding the current variant used for disambiguation. Update: Replace `tclTypes.c`, `tclTypes.h`, `tclTypePath.c`, and `tclAnnotObj.c` in the `generic/` directory, then run `make`. There is no kernel patch; `maj.sh` handles the update. (user: Florentis, size: 1751) [annotate] [blame] [check-ins using]
sans règle 1 the current variant of temp is "celsius", not "fahrenheit"; both have the same form, so reading one as the other needs a rule: type convert temp.celsius temp.fahrenheit {{x} ...} cast sans règle 1 the current variant of temp is "celsius", not "fahrenheit"; both have the same form, so reading one as the other needs a rule: type convert temp.celsius temp.fahrenheit {{x} ...} t(fahrenheit) 0 212.0 double t(celsius) 0 100 cast 0 212.0 temp.fahrenheit cast retour 0 100.0 temp.celsius cast même variante 0 100 temp.celsius type cast 0 212.0 temp.fahrenheit t inchangé 0 100 temp.celsius écrire changer 0 50 temp.fahrenheit déduction : ambigu 1 value "5" fits variants celsius and fahrenheit of temp equally: write {celsius}5, or set {temp}y(celsius) 5 S i lu s (cast) 0 5 string S s lu i (cast) 0 12 int S s abc lu i 1 the current variant of S is "s", not "i", and its value "abc" can't be read as int S s abc lu i, règle 0 3 règle qui rend faux 1 non erreur : sommes ≠ 1 type convert between variants needs two variants of the same sum, as in S.a S.b, not "temp.celsius" and "S.i" erreur : variante ? 1 type convert: temp has no variant "kelvin" erreur : même 1 type convert: "temp.celsius" and "temp.celsius" are the same variant erreur : mêlé 1 type convert between variants needs two variants of the same sum, as in S.a S.b, not "temp.celsius" and "double" liste de temp 0 212.0