Artifact cbcd12c108ea88f5d0e77d4bb6f957a8ead461e812ced64d36d40945dc66a1a3:
- File typeparse/tests_tclsh/t28_type_deref.tcl.out — part of check-in [1508c3d76a] at 2026-11-05 08:59:55 on branch tip-764_tcl90 — Version 16p adds a field to the `Proc` structure. It allows for the typing of both the return value and the arguments of procedures. Example: tcl proc {pt}decale { {pt}p; {double}dx ?= 0; {double}dy ?= 0 } { set {pt}q [expr {$p(x) + $dx}] [expr {$p(y) + $dy}] return $q } set {pt}a 1 2 decale $a 1 1 ;# positional decale $a {dy:}5 ;# positional, followed by labels decale {dy:}5 {p:}$a ;# labels only, in any order Arguments Fields: Each field becomes a local variable subject to its defined contract. Defaults: `?= v` or `?= [cmd]`—evaluated at each procedure call; it may reference preceding fields. Remainder: A final field, `{list.T}args`, collects any excess arguments, each of which is validated. Automatic `upvar`: `{var.T}n` binds `n` to a variable in the callers scope, with its current value being validated. Call-site labels: Positional arguments following a label are disallowed; providing the same field twice or using an unknown label will also result in an error. Exception: If the target field is a sum type, the label selects the specific variant (e.g., `ps {s:}abc`). Messages: These take forms such as `wrong # args: should be "decale p ?dx? ?dy?"` or `argument "dx": expected floating-point number but got "abc"`. Return Value Cast: `proc {T}name` casts the result of a standard `return` to type `T`. Errors, `break`, `return -level 2`, `tailcall`, and `yield` are not subject to this cast. Local annotation: `return {U}$x` simply attaches an annotation, which expires when the procedure terminates. There is, therefore, no type overlapping (or "cumulation" of types). Tags: When a return value is a sum type, `return {point:}$z` selects the specific variant, and a strict sum type (`-strict`) mandates it. Using a tag that is not a valid variant, or applying one to a return value that is not a sum type, results in an error. Introspection and compatibility `type proc name returns args {…} return T`—`info args` and `info default` can "see" the fields. A valid Tcl list remains a standard list of arguments. An initial attempt caused the `proc-old-5.4` test to fail (due to an unclosed brace); this has been fixed, and the standard error is now correctly returned. Performance cost: A call with 3 arguments takes 1.2 µs, compared to 0.6 µs for an equivalent standard procedure. The return-type cast incurs no overhead if the value is already of the correct type. See next commit for complements (user: Florentis, size: 684) [annotate] [blame] [check-ins using]
liens : ::A ::B ::C valeurs : 1 2 3 (list<int>) le lien suit B (20), l'instantane reste fige : 1 2 3 nouvel instantane : 1 20 3 1 type deref: at 2: can't read "::C": no such variable refs inchange : ::A ::B ::C dict : x 1 y 20 (dict<int>) imbrique: {1 20} {20 1} (list<list<int>>) produit : 1 hello (deref(lien)) sans lien : 1 2 (list<int>) var brut : 1 un niveau : ::A deux fois : 1 1 type deref: at 0: can't access "frame:1:local": the procedure call that owned this variable has returned 1 type deref needs a typed value 1 wrong # args: should be "type deref value" 1 bad subcommand "zz": must be def, alias, cast, convert, deref, export, forget, get, is, proc or binary