You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think enums without a default variant should throw an error at compile time if they try to derive starknet::Store - otherwise, attempting a storage read on an uninitialized slot will cause a runtime panic.
it is the decision of the contract writer to know they only are reading valid values.
I consider it an issue because I don't think reading a value from storage should default to a panic if that value is not set. By ensuring a default variant exists, you are leveraging the compiler so that:
You catch eventual errors at compile time by forcing a variant to act as the default one - if required, the contract creator can just add a None variant that fulfills this role.
You force the definition of a type associated to an empty storage
You can "clear" an enum in storage by resetting it to the default variant
Contract creator might not now about this default panic scenario (as reported in the issue) - I actually did not even know about this.
I think enums without a default variant should throw an error at compile time if they try to derive
starknet::Store
- otherwise, attempting a storage read on an uninitialized slot will cause a runtime panic.See description in cairo-book/cairo-book#990
The text was updated successfully, but these errors were encountered: