← board

feature: default parameter values

Gap

A parameter with a default value is rejected at parse:

function f(a: integer; b: integer = 10): integer; begin f := a + b; end;
begin writeln(f(5), '|', f(5, 1)); end.
{ fpc: 15|6    pxx: error: unexpected token  (at '=') }

Expected

Accept param: type = constexpr in a routine signature; a call that omits the argument supplies the default (f(5)a=5, b=10). Defaults must be trailing and constant-foldable (FPC rules).

Track B impact

Library APIs must either overload or require all arguments. Low-risk to live without, but it is a routine convenience used throughout idiomatic Pascal.

Repro

tools/fpc_diff_probe.sh (default-param).

Resolution (2026-06-23)

Default values for trailing parameters, constant-folded (ordinal/char/bool/enum):

f(5)=15, f(5,1)=6; multi/partial defaults g(1)/g(1,20)/g(1,20,300)=103/121/321; Boolean default p(7)/p(8,false). Byte-identical self-host (inert for exact-arity calls; no existing code uses defaults). Limitation: ordinal-foldable defaults only (string/float defaults not yet). Gate: full make test (ir + overload reach). Closes feature-default-parameters.