Core Solidity introduces algebraic data types (ADTs) and pattern matching to eliminate a class of smart contract bugs that Classic Solidity cannot catch at compile time. Classic Solidity's enum+struct approach allows invalid states to be represented and provides no compile-time guarantee that all variants are handled when new ones are added. ADTs make invalid states unrepresentable by bundling each constructor with exactly its required fields. Pattern matching with exhaustiveness checking forces developers to handle every variant, turning missed cases into compile errors rather than silent runtime failures. The compiler uses a decision-tree algorithm (based on Maranget's work) to detect non-exhaustive and redundant patterns, providing concrete witness examples in error messages. Crucially, this adds zero runtime overhead: the generated Yul is identical to a hand-written tagged union switch statement, with all safety checks happening entirely at compile time.

15m read timeFrom soliditylang.org
Post cover image
Table of contents
Why Classic Solidity Needs Better Data ModelingAlgebraic Data Types Make Invalid States UnrepresentableTotality: Exhaustiveness as a Safety PropertyThe Pattern Match CompilerLowering to Yul: Why There Is No OverheadConclusion

Sort: