Artifact 4670cf38a1d64e5dbb2b2c9f597872525b1f96c03ff07a794193269a5bf84a8d:
- File typeparse/tests_tclsh/t66_variantes_meme_forme.out — part of check-in [b00991eb89] at 2026-10-23 11:07:57 on branch tip-764_tcl90 — Let’s address the point: "Variants with the same form—if multiple equally strict variants are applicable, trigger an error; the error message should suggest `{variant}value` and `set {S}v(variant) value`, while ensuring the deduction defaults to the strictest variant." This is now implemented: v15m is included in `typeparse.zip`. The item has been marked as complete in the project schedule and noted in `noyau/LISEZMOI.md` as well as `doc/ANNOTATIONS.fr.md` (section 8; it has also been removed from section 17). Regarding the error message: The deduction logic selects the strictest variant (e.g., given `{int}i` and `{string}s`, the value `5` resolves to `i`, as before). If multiple equally strict variants are applicable, an error is raised: `set {A}v 5` ;# the value "5" fits variants `i` and `j` of `A` equally: write `{i}5` or `set {A}v(i) 5` The suggested syntax `set {A}v(i) 5` includes the variable name and only appears when an assignment is made directly to the sum type itself. In the context of a list or a product, the message simply suggests `{i}7`. The same logic applies to variants that have no defined precedence relative to one another (e.g., `{P}p` and `{Q}q` with `{1 2}`). For identical anonymous variants (e.g., `{int}`, `{int}`), since there are no labels to reference, the message instructs the user to "name the variants to choose one." A discovery made along the way: With this error check in place, many previously valid cases began to fail. In v15, these cases had passed because the chosen variant was silently discarded, defaulting back to `i`. This occurred in scenarios such as: assignments within a list (`set {list.A}L $v`); assignments within a product (`set {R}r $v 1`); operations like `incr v`, `set v 8`, `lset`, or `set L(0) …`; and type casts—such as `A {j}5` or even `B {s}5`—which previously resolved to `B.i`. I have also addressed these instances of lost information: Lists and products: an element or field whose content alone does not uniquely identify its variant now retains its annotation. (The validation process was already re-reading this information.) Type casts: the label beneath the type of a sum now explicitly names the variant. A design decision to confirm: for a modification (e.g., `set v 8`, `incr v`, `set L(0) 4`, `lset L 0 9`, `set r(a) 7`), I have configured it to preserve the current variant when multiple variants are equally valid. Otherwise, an operation like `incr v` on an `A.j` would trigger an error. If you would prefer to have an error in all such cases—based on the principle that "a modification is a computation"—this can be changed by removing four lines of code. Tests against v15: The same differences as before, plus `t65`, with no other changes. All expected `.out` outputs pass. The Tcl tests—`set`, `var`, `upvar`, `lset`, `list`, `lindex`, `append`, and `incr`—result in 1,234 successes out of 1,251, with 17 skipped and zero failures (across both trees). `valgrind` reports no issues for the new test cases. New test added: `t66_variantes_meme_forme`. (user: Florentis, size: 1499) [annotate] [blame] [check-ins using]
-- déduction B 5 : int, la plus stricte 0 B.i B 2.5 0 B.d B abc 0 B.s A 5 : i et j 1 value "5" fits variants i and j of A equally: write {i}5, or set {A}v(i) 5 C {1 2} : p et q 1 value "1 2" fits variants p and q of C equally: write {p}{1 2}, or set {C}v(p) {1 2} W 5 : anonymes 1 value "5" fits variants #1 (int) and #2 (int) of W equally: name the variants to choose one A {j}5 0 A.j A v(j) 5 0 A.j type cast A 5 1 value "5" fits variants i and j of A equally: write {i}5 type cast A {j}5 0 A.j type cast B {s}5 0 B.s -- la variante survit copie 0 A.j liste 0 A.j A.i liste nue 1 value "7" fits variants i and j of A equally: write {i}7 lappend 0 A.j lappend nu 1 value "3" fits variants i and j of A equally: write {i}3 produit 0 {5 1} A.j produit {a} 0 A.j B {s}5 dans une liste 0 B.s -- modifications : la variante courante départage set v 8 0 8 A.j incr v 0 6 A.j set v(i) 8 0 A.i set v {i}8 0 A.i L(0) 4 0 A.j lset L 0 9 0 A.j r(a) 7 0 A.j r(n) 2 0 A.j