Design decisions

98. Reject ++, numeric-only unary +, fmt AST equivalence, and indented lambda block bodies (2026-11-21)

  1. ++ is a lexer error ("CP Lang concatenates with +") with a + fix-it; unary + is numeric-only (E0302 otherwise); cpl fmt corpus test checks parsed AST equivalence.
    • Reason: Previously xs ++ [v] ++ ys lexed as + followed by unary +, the parser silently dropped unary +, and cpl fmt rewrote it to xs + +[v] + +ys which ran on List. Now UnOp::Pos is preserved in the AST, checked as numeric-only (E0302 on non-numeric operands), ++ is rejected in cpl-syntax::lexer with a machine-applicable + fix-it (applied by cpl fix), and cpl-fmt::tests::formats_the_whole_corpus compares span-stripped parsed ASTs before and after formatting across all 1000+ corpus .cp files.
    • Reverse: Remove the (b'+', b'+', _) arm in crates/cpl-syntax/src/lexer.rs and UnOp::Pos across cpl-syntax/cpl-check/cpl-ir/cpl-interp/cpl-codegen.
  2. Indented block bodies after => on lambdas and table comprehensions, plus bracketed match/if/else blocks.
    • Reason: Accepted syntax so multi-statement lambdas work cleanly in table comprehensions ([0..=s, 0..n] (i, j) =>\n ...), named arguments (by: x =>\n ...), and call arguments without wrapping in braces. The lexer tracks layout_blocks inside brackets so Newline/Indent/Dedent tokens are emitted for => blocks (and match/if/else blocks ending in :) inside (...)/[...], split_items keeps bracketed items intact, and Parser::lambda_body parses Newline + Indent into ExprKind::Block(Block) whose value is its last expression (matching fn ... :, formatter, LSP folding, and --trace).
    • Reverse: Remove layout_blocks in crates/cpl-syntax/src/lexer.rs, brackets in crates/cpl-syntax/src/items.rs, and lambda_body in crates/cpl-syntax/src/parser/expr.rs.