2026-10-23 10:32:49
— part of check-in
[eb4d87204c]
on branch tip-764_tcl90
— Error messages now explicitly name the variants (v15k). Additionally, reading from an inactive variant can now succeed; this is a change in behavior that should be verified.
The source
Reading a variant other than the current one constitutes an explicit cast, according to the specification (§ 10). However, the code was performing the cast from the entire sum type—specifically, from `S` to `string`. Since no rule exists for converting a sum type into one of its constituent variants, the system previously returned the unhelpful error: "unknown way to cast the value from S to string."
The fix
The cast is now performed based on the value of the current variant:
set {S}v {i}5
$v(s) -> 5 (the 5 from variant `i`, read as a `string`)
set {U}u {n}3
$u(p) -> the current variant of U is "n", not "p", and its value "3" can't be read as `p`
Regarding write operations, there are two scenarios:
Writing to a variant changes the variant, as before: `set v(s) abc` results in `S.s`.
Writing to a component of an inactive variant is still disallowed, but the error message now provides guidance:
set u(p.x) 1 -> the current variant of U is "n", not "p": to change the variant,
write the whole value ({p}...)
The suggested write operation works: `set u {p}{1 2}` results in `U.p`.
Verifications
Project tests and examples yield the same results as before, including those for `arduino` and `cstruct`, which utilize sum types. Tests `t35` through `t63` retain their expected outcomes.
Update
`tclTypePath.c` only (without kernel patch), followed by `maj.sh`.
New test case: `t64_variante_inactive`. The v15k section in kernel/README.md.
The “sum” line in the French documentation’s path table, now completed. I removed the bullet point from § 17 and checked off the corresponding item in the planning document.
For your approval: previously, $v(s) on an {i}5 would always fail. Now, it returns 5, in accordance with the explicit cast rule. If you would prefer that reading an inactive variant always result in an error—with the same error message—it’s just a single line that needs changing.
(user:
Florentis,
size: 575)
[annotate]
[blame][check-ins using]
2026-11-27 09:47:31
— part of check-in
[eacc36058b]
on branch tip-764_tcl90
—
v17z
Review of sum type notation.
- A variant of a sum is metadata, it must not appeat into the value :
If there is ambiguity to choose a variant of a sum, it must be an error.
- New commands to request variants of a sum type, or of a litteral sum :
type variant $v ?NAME? : empty for a litteral ; NAME select the variant of the value.
type variant -of T ?NAME?
type literal -of T ;
type is {sum?}T
type is {enum?}T
- New command to compare the type of a value :
type eq T1 T2 : true is types T1 and T2 are equal
type include T1 T2 : true if type T2 is included into T1
- New type 'num'
(user:
Florentis,
size: 575)
[annotate]
[blame][check-ins using]