Artifact 6c4756fc344253cb605b8d60e767a2135c9782ba7a1c1a1fd1c1f955984c3294:
- File typeparse/tests_tclsh/t93_piste_b.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: 2085) [annotate] [blame] [check-ins using]
--- plus de fuite : l'erreur ne sort plus d'un catch catch {concat {int}$s} r: 0 {3.0 {} int} string cat: 0 {3.0 {} int} lindex: 0 {3.0 {} int} return {int}$s: 0 {3.0 {} int} procédure, concat: 0 {3.0 {} int} return -level 0: 0 {3.0 {} int} if: 0 {3.0 {} int} élément d'une liste: 0 {3.0 {} int} eval: 0 {3.0 {} int} subst: 0 {3.0 {} int} set y [concat ...]: 0 {3.0 {} int} {dict} non vérifié: 0 {{a b c} {} dict} --- le constructeur qui reçoit le mot résout toujours set _ {int}$s: 1 {expected integer but got "3.0"} set {int}i 5: int nom calculé : déclaration: int nom calculé : [set nom]: double étiquettes: 3 4 contrat: 1 {expected integer but got "3.0"} --- type {T}mot : le cast explicite type {int}$s: 1 {expected integer but got "3.0"} type {double}$s: 3.0 double {} type {list}$p: {1 2} list {} type {dict}$p: {x 1 y 2} dict {} type {int}[cmd]: 5 int {} type {int}[(expr)]: 5 int {} type {int}"…": 44 int {} type {int}5: 5 int {} nom inconnu: 1 {unknown type "zz"} annotation locale: 1 {"-v" is not a type: "type" casts to a type} sans annotation: 1 {bad subcommand "5": must be def, alias, cast, convert, deref, export, forget, get, is, proc or binary} dans un catch: 1 {unmatched open brace in list} --- les boucles reçoivent leurs listes foreach {list}$p: 1/2 lmap {list}$p: 3 dict for {dict}$p: x=1 y=2 dict map {dict}$p: x 10 y 20 lassign {list}$p: 1 2 foreach : erreur attrapée: 1 {unmatched open brace in list} lassign : erreur attrapée: 1 {unmatched open brace in list} compilées dans une procédure: 3-4 12 x y {x 4 y 5} 3 4 1 {unmatched open brace in list} --- listes typées : lappend et lset reçoivent l'élément list.any, list.S: double string S.s S.i au niveau global: int string --- notes expirées : des métadonnées note posée, passée par concat: 5 {} mm type def ensuite: 5 {} mm2 rangée par set: 5 {} mm3 note delete: 5 {} b --- boucles compilées : {T}mot casté une fois (annotCast) castes: int 1 {expected integer but got "a"} 1 {list(3)<int> needs exactly 3 elements but got 2} 1 {unmatched open brace in list} {a {} b {}} 1 2 30