motoko icon indicating copy to clipboard operation
motoko copied to clipboard

experiment: migration functions trigger use-before-define errors

Open crusso opened this issue 5 months ago • 2 comments

I had a hunch that using a migration function would allow you to apply a stable function before it is properly defined. Turns out to be true...

This is a simple variation of the existing, simpler test dropping-stable-functions that, in a twist, uses the migration function to call a stable function that references an earlier stable variable (uninitialized) before it has been defined, leading to a crash.

crusso avatar Aug 06 '25 13:08 crusso

Good catch. Thanks for identifying. I fixed in meantime: 8ceede90205cdc4366437aa9a0a4b17c113cf0a9 I guess persistent function calls can be disallowed during migration.

luc-blaeser avatar Sep 05 '25 18:09 luc-blaeser

Improved version that allows safe persistent function calls during migration: E.g. accessing persistent class methods of object-oriented data structures during migration. https://github.com/dfinity/motoko/pull/5462

luc-blaeser avatar Sep 10 '25 12:09 luc-blaeser