Radar · Solidity · Archive · Week 19 · May 5 – 11, 2025
NatSpec captures enum value documentation in the AST
Nice to knowlanguage
- What changed
- The compiler now includes NatSpec documentation of enum values in the abstract syntax tree.
- Production impact
- The source does not say.
- Try it
- Use the Solidity compiler’s AST output to check that enum value comments appear.
- Source
- github.com/argotorg/solidity/releases/tag/v0.8.30
Understand it, then run it
The compiler now records the documentation you write for each member of an enum. When you add a NatSpec comment above an enum value, that comment becomes part of the compiler’s abstract syntax tree (AST). This means tools that read the AST can show the description of each enum value. The change does not affect how you write or use the enum itself.
Run it now
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.37;
// This contract demonstrates that NatSpec documentation on enum values
// is now captured in the compiler's AST (as of Solidity 0.8.30).
// The enum below has NatSpec comments for each value.
contract EnumWithNatSpec {
/// @notice The first state
enum State { Pending, Approved, Rejected }
State public current;
constructor() {
current = State.Pending;
}
function approve() external {
current = State.Approved;
}
function reject() external {
current = State.Rejected;
}
}
Tests
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.37;
import "./main.sol";
contract EnumWithNatSpecTest {
EnumWithNatSpec instance;
constructor() {
instance = new EnumWithNatSpec();
}
function test_initialState() external {
require(
uint8(instance.current()) == 0,
"Initial state should be Pending (0)"
);
}
function test_approve() external {
instance.approve();
require(
uint8(instance.current()) == 1,
"State should be Approved (1) after approve()"
);
}
function test_reject() external {
instance.reject();
require(
uint8(instance.current()) == 2,
"State should be Rejected (2) after reject()"
);
}
}
The test report when we ran it on Solidity 0.8.37 (solc)
3 of 3 tests passed.
- test_approve49,382 gas
- test_initialState28,628 gas
- test_reject49,437 gas
- EnumWithNatSpecTest: 1,458 bytes of bytecode, deployed for 395,228 gas
solc 0.8.37 · prague
Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.
Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed