Skip to content

bytes.concat cannot be used for initializating constant #16188

@CJ42

Description

@CJ42

Description

When defining a constant variable of type bytes and initializing with some bytes that are concatenated together:

  • the method abi.encodePacked(...) works ✅
  • but not the method bytes.concat(...)

Environment

  • Compiler version: 0.8.30
  • Compilation pipeline (legacy, IR, EOF): none
  • Target EVM version (as per compiler settings): cancun
  • Framework/IDE (e.g. Foundry, Hardhat, Remix): Foundry

Steps to Reproduce

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.30;

contract Example {

    // ✅ Compile successfully
    bytes public constant A = abi.encodePacked(
        hex"aaaa",
        hex"bbbb",
        hex"cccc"
    );

    // ❌ TypeError: Initial value for constant variable has to be compile-time constant.
    bytes public constant B = bytes.concat(
        hex"aaaa",
        hex"bbbb",
        hex"cccc"
    );

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛low effortThere is not much implementation work to be done. The task is very easy or tiny.low impactChanges are not very noticeable or potential benefits are limited.must have eventuallySomething we consider essential but not enough to prevent us from releasing Solidity 1.0 without it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions