I was playing around with this in icp.ninja and started getting some weird behavior after using the new migrations syntax in combination with record merging.
Below is a screenshot, where I made a deployment that had a stable variable in the canister reinitialized that was used for calculating the new state, but that wasn’t explicitly returned as a part of the new migration. Instead, I used the record merging syntax.
The warning/error shown when highlighting is:
migration expression consumes field `incorporateState` of type
Nat
but does not produce it, yet the field is declared in the actor.
The declaration in the actor will be reinitialized, discarding its consumed value.
If reinitialization is unintended, and you want to preserve the consumed value, either remove this field from the parameter of the migration function or add it to the result of the migration function.(M0206
The upgrade succeeds, but then every time I try to return the value of incorporateState() with a query call, Ninja returns odd behavior. First a trap message returns with
[13:41:59.593] [TRAP]: stable variable `incorporateState` of type `Nat` expected but not found
But then the value of the variable also returns
(7)
I then upgraded the canister again, and started getting a more troubling RTS error: Memory-incompatible program upgrade
error after the upgrade, with the same trap + correct response behavior.
Did I hit a bug?