Artifact c7312eb9a57827d863bd75ea1ebdfe72da884e4403e037f03eee5fa87bdacecc:
- File typeparse/tests_tclsh/t22_somme_balisee.tcl — part of check-in [43c57f18b6] at 2026-11-04 08:32:02 on branch tip-764_tcl90 — What v16n introduces: `type is {disjoint?}S` returns the pairs of variants that can accept the same value; it returns nothing if the sum is disjoint. `type is {strict?}S` is also available. `type def {-strict}S`: the variant is never inferred (guessed). A "bare" value is rejected: "value 5 names no variant of the strict sum S: write `{i:}value` or `{S.i}value`." Accepted forms include: an already-typed value, a label such as `{i:}` or `{S.i}`, or a type cast like `S.i`. A variant literal is identified by its value, and when stored in a typed variable, the current variant is preserved. `type def {-deduce}S` retains the previous behavior: the strictest variant takes precedence. Warning: An overlapping sum defined without any options will trigger a message on `stderr` suggesting either `{-deduce}` or `{-strict}`. A disjoint sum will not trigger such a message. Multiple options: `{-compact, -strict}` can be used within the annotation syntax. The structure is flattened (e.g., `{-a.(b=1, c=2)}` becomes `-a.b=1` and `-a.c=2`), meaning sub-option syntax is supported. Currently, no `type def` options utilize this; for instance, `{-strict.x=1}` will result in a clear error message. (user: Florentis, size: 1402) [annotate] [blame] [check-ins using]
# Somme dont deux variantes ont la même forme : la balise explicite fixe la # variante, aussi dans une liste de sommes, y compris avec lappend. set nfail 0 proc check {what got want} { global nfail if {$got eq $want} {puts "ok: $what"} else {incr nfail; puts "ECHEC: $what -> '$got' (attendu '$want')"} } type def texte {{string}keyword; {string}text} type def autre {{string}name; {string}hex} type def {-deduce}bloc {{texte}tEXt, {autre}inconnu, {string}IEND} set {texte}t {keyword:}Comment {text:}bonjour set {autre}a {name:}zzzz {hex:}00ff check "scalaire tEXt" [type get [set {bloc}b {tEXt:}$t]] bloc.tEXt check "scalaire inconnu" [type get [set {bloc}c {inconnu:}$a]] bloc.inconnu check "sans balise : ambigu" [catch {set {bloc}d {Comment bonjour}} m] 1 set {list.bloc}L {tEXt:}$t {inconnu:}$a {IEND:}{} check "liste" [lmap e $L {type get $e}] {bloc.tEXt bloc.inconnu bloc.IEND} check "accès tEXt" $L(0.tEXt.keyword) Comment set {list.bloc}M lappend M $b lappend M $c check "lappend de sommes typées" [lmap e $M {type get $e}] {bloc.tEXt bloc.inconnu} proc enproc {t a} { set {list.bloc}N lappend N [set {bloc}x {tEXt:}$t] lappend N [set {bloc}y {inconnu:}$a] lmap e $N {type get $e} } check "lappend en procédure" [enproc $t $a] {bloc.tEXt bloc.inconnu} check "champ de la variante" [set b(tEXt.text)] bonjour puts [expr {$nfail ? "$nfail ECHEC(S)" : "tout est ok"}]