Design decisions

169. Named-argument and record-field punning f(x:) (2026-11-21)

  • Decision. A named call argument or parenthesized record field whose value is a variable of the same name may be written in punned shorthand: f(moves:, cost:, step:) means f(moves: moves, cost: cost, step: step), and (moves:, cost:) means (moves: moves, cost: cost).
  • Mechanism. Parser-only desugaring in Parser::arg and ExprKind::Record (crates/cpl-syntax/src/parser/expr.rs): when a name: label is immediately followed by , or ), the parser builds ExprKind::Name(name) at name.span. No checker, IR, interpreter, or C++ codegen special case is needed; LSP hover resolves the local's type through the synthesized expression span. cpl-fmt preserves tokens strictly and formats punned calls/records without spaces before : or ,. Lint L0209 (redundant_arg_name) warns on name: name with a machine-applicable cpl fix to name:.
  • Evidence. Corpus audit found 155 exact name: name sites across 54 port files and 75 across 10 stdlib files (52 reviewed port files and all 10 stdlib files migrated via L0209; 2 unreviewed ports left untouched for review-check). Interp/C++17 parity test crates/cpl-cli/tests/programs/named_arg_punning.cp (345 12 7), formatter test formats_punned_named_args_and_records, LSP test hover_on_punned_named_arg_shows_local_type, lint test redundant_arg_name_shortens_to_punning, and docs in site/content/types-and-control.md.
  • Reverse. Remove the punning branch in Parser::arg and ExprKind::Record, remove L0209, and expand name: back to name: name.