Enums with data / sum datatype / algebraic datatypes
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 21
Description
This is a story that already exists is pivotal tracker.
Solidity should support sum datatype similar to how they are supported by rust.
```
// Enum holding additional data (marked union / sum datatype)
enum Commitment {
Hidden(bytes32 hash),
Revealed(uint value)
}
function reveal(Commitment storage self, uint _value, uint _nonce) {
if (self == Commitment.Hidden && self.Hidden.hash == sha3(_value, _nonce))
self = Commitment.Revealed(_value);
}
```
Comparison between enum types and enum field names (like `Commitment.Hidden`) is done based on the enum value only (data is ignored) but comparisons between enum variables is a deep comparison.
Because of the fact that references to the storage location of `self.Hidden.hash` can be kept, while `self` is switched to `Revealed`, the storage and memory locations of `Commitment.Hidden.hash` and `Commitment.Revealed.value` cannot overlap.
Contributor guide
Research direction
The issue names no source files, tests, or entry points. Start by reviewing how Solidity currently represents enums and compare the requested syntax and semantics with Rust; done requires an accepted design for storage, memory, comparisons, and state transitions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- solidity
- Domain
- blockchain, compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100