ink icon indicating copy to clipboard operation
ink copied to clipboard

Allow enum to implement SpreadAllocate

Open forgetso opened this issue 2 years ago • 2 comments

Recently, the contract implementation style has changed so that the contract struct derives SpreadAllocate.

This causes a compilation error in contracts that make use of enum with more than one variant. This is because it is not possible to determine a default value, so SpreadAllocate is not defined for enum.

It would be nice if enum was allowed if the Default trait was implemented.

e.g. https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=21d9e01c332a660d9e5ab22634250f1a

Here is my hacked version of making this work in ink: https://github.com/prosopo-io/ink/commit/bdc676d61804a3fd88f76cb8045238250b3db166

forgetso avatar Nov 24 '21 16:11 forgetso

@forgetso do you know in current version of Ink if we still need to implement SpreadAllocate for enum?

ceikit avatar May 15 '22 13:05 ceikit

Yes, you still need to implement SpreadAllocate for all types that are part of the storage(For enums it should be done manually). It will be changed after resolving https://github.com/paritytech/ink/issues/1134

xgreenx avatar May 15 '22 15:05 xgreenx

This is not an issue in ink! 4.0 anymore due to https://github.com/paritytech/ink/issues/1134

HCastano avatar Feb 22 '23 21:02 HCastano