Error Lab
Every diagnostic below is the real output of ptc, not a mock-up. Pick a mistake, read how the compiler teaches the canonical form, then flip to the fix.
A parameter is never mut
Parameters are immutable and cannot be declared mut — every capability (Rng, Fs, Clock…) arrives as one. A draw or a push therefore starts with a mutable copy, and the error writes that copy for you.
fn roll(dice: Rng) -> Int:
return dice.int(1, 6)
print("{roll(fixed_rng(7))}")The compiler answers
error: cannot call 'int' on immutable 'dice' — it advances the generator; 'dice' is a parameter, and parameters are immutable — bind a mutable copy first: 'mut my_dice = dice', then use 'my_dice' (line 2, column 12)fn roll(dice: Rng) -> Int:
mut my_dice = dice
return my_dice.int(1, 6)
print("{roll(fixed_rng(7))}")Fixed — and it runs
4