Document that enum-to-integer casts are not allowed for signed integer targets
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- solidity
- Domain
- documentation
Research direction
Open the linked Solidity Types documentation and read the Enums section, then compare its conversion wording with the supplied solc CLI reproduction, including int256(e) and the unsigned-cast workaround. Done means the documentation clearly states whether enum-to-signed-integer casts are allowed and explains the relevant restriction or workaround.
Written by the indexing model from the issue text.
Description
The Solidity documentation says:
Enums are one way to create a user-defined type in Solidity. They are explicitly convertible to and from all integer types but implicit conversion is not allowed.
However, casting an enum value to an unsigned integer is accepted, and casting a signed integer to an enum is accepted and checked at runtime, but casting an enum value to a signed integer is rejected during type checking. This seems inconsistent because enum values are non-negative small integer values, so converting an enum to a sufficiently wide signed integer such as int256 should be representable.
Expected behavior: either int256(e) should compile when the target signed integer type can represent all enum values, or the documentation should clarify that enums are not explicitly convertible to signed integer types.
Environment
- Compiler version:
0.8.35-develop.2026.5.5+commit.47b9dedd.Linux.g++ - Compilation pipeline (legacy, IR, EOF): default
- Target EVM version (as per compiler settings): default
- Framework/IDE (e.g. Foundry, Hardhat, Remix): solc CLI
- EVM execution environment / backend / blockchain client: N/A
- Operating system: Ubuntu Jammy on Linux
5.15.0-173-genericx86_64
Steps to Reproduce
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
contract C {
enum E {
A,
B
}
function enumToUint(E e) external pure returns (uint256) {
return uint256(e); // OK
}
function enumToSignedInt(E e) external pure returns (int256) {
return int256(e); // Rejected
}
function signedIntToEnum(int256 x) external pure returns (E) {
return E(x); // OK, runtime-checked
}
}
Actual result:
TypeError: Explicit type conversion not allowed from "enum C.E" to "int256".
The current workaround is an intermediate unsigned cast:
return int256(uint256(e));
That workaround compiles, but the need for it is not apparent from the documented enum conversion rule.
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 27
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from argotorg/solidity
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
documentation :book:
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug :bug:
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug :bug: low impact
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
bug :bug: low impact
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
All issues in argotorg/solidity
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
bug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
NVIDIA/cuda-samples#453 ·