Artifact 61e977f03c49a82e7eff8195e256944c71505e453c2c781be760ec4a2796d2e6:
- File typeparse/tests_tclsh/t57_selecteur.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: 1457) [annotate] [blame] [check-ins using]
# t57 : somme choisie par un champ, S($champ) : la variante vient du sélecteur, # même quand plusieurs variantes ont la même forme ({u8}, {u8; u8}). source [file join [file dirname [file normalize [info script]]] .. layout filebinary.tcl] source [file join [file dirname [file normalize [info script]]] .. layout binaliases.tcl] proc attempt {script} { set c [catch {uplevel 1 $script} r] puts "$c: [lindex [split $r \n] 0]" } type def c_mode {{u8}broche; {u8}mode} type def c_lire {{u8}broche} type def c_pwm {{u8}broche; {u8}rapport} type def {-deduce}corps {{c_mode}1, {c_lire}3, {c_pwm}4} type def req {{u8}genre; {corps($genre)}corps} foreach octets [list "\x04\x09\x80" "\x01\x09\x01" "\x03\x0e"] { set r [type binary decode req $octets] puts "décodé : $r -> [type get $r(corps)]" } set r [type binary decode req "\x04\x09\x80"] puts "chemin : broche $r(corps.4.broche) rapport $r(corps.4.rapport)" set {req}a 4 {9 128}; puts "construit : [type get $a(corps)]" set {req}b(corps,genre) {9 1} 1; puts "nom/valeur, sélecteur après : [type get $b(corps)]" set a(corps.4.rapport) 60; puts "écriture par chemin : $a" attempt {set a(genre) 3} set a(genre) 1; puts "sélecteur changé : [type get $a(corps)]" binary scan [type binary encode req $a] cu* o; puts "encodé : $o" set {c_pwm}p 9 200 attempt {set {req}c 1 $p} attempt {set {req}d 3 {4:}{9 1}} attempt {type binary decode req "\x09\x01"}