Document that enum-to-integer casts are not allowed for signed integer targets

Open Beginner friendly
#16,677 1 comment 0 reactions 0 assignees View on GitHub

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

bug :bug: documentation :book: low effort low impact should have

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-generic x86_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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from argotorg/solidity

All issues in argotorg/solidity

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.