Skip to content

bug(forge fmt): fmt fails when encounters layout #10660

@gnkz

Description

@gnkz

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge Version: 1.2.1-stable

What version of Foundryup are you on?

No response

What command(s) is the bug in?

forge fmt

Operating System

Linux

Describe the bug

When running forge fmt on contracts that have variables/functions called layout it fails with

Error: Failed to parse Solidity code for src/Counter.sol. Leaving source unchanged.

Context:
- failed to parse file:
Error: ParserError
   ╭─[ :7:14 ]
   │
 7 │     function layout() public view returns (uint256) {
   │              ───┬──
   │                 ╰──── unrecognised token 'layout', expected identifier, "(", "revert", "at", "leave", "switch", "case", "default"
───╯
Error: ParserError
   ╭─[ :7:20 ]
   │
 7 │     function layout() public view returns (uint256) {
   │                    ┬
   │                    ╰── unrecognised token '(', expected "at"
───╯
Error: ParserError
   ╭─[ :8:9 ]
   │
 8 │         return counter;
   │         ───┬──
   │            ╰──── unrecognised token 'return', expected identifier, annotation, string, hexstring, address, number, rational, hexnumber, ";", "}", "(", "[", Uint, Int, Bytes, "byte", "struct", "bool", "address", "string", "bytes", "event", "enum", "type", "true", "false", "payable", "constructor", "function", "mapping", "receive", "fallback", "at", "using", "modifier", "leave", "switch", "case", "default"
───╯
Error: ParserError
    ╭─[ :12:21 ]
    │
 12 │         uint256 $ = layout();
    │                     ───┬──
    │                        ╰──── unrecognised token 'layout', expected identifier, string, hexstring, address, number, rational, hexnumber, "(", "+", "-", "!", "~", "++", "--", "[", Uint, Int, Bytes, "byte", "bool", "address", "string", "bytes", "delete", "new", "type", "true", "false", "payable", "function", "revert", "mapping", "at", "leave", "switch", "case", "default"
────╯
Error: ParserError
    ╭─[ :12:27 ]
    │
 12 │         uint256 $ = layout();
    │                           ┬
    │                           ╰── unrecognised token '(', expected "at"
────╯
Error: ParserError
    ╭─[ :18:18 ]
    │
 18 │         counter++;
    │                  ┬
    │                  ╰── unrecognised token ';', expected identifier, "{", "(", "++", "--", "[", ".", "memory", "calldata", "storage", "transient", "public", "private", "external", "internal", "constant", "revert", "at", "override", "immutable", "leave", "switch", "case", "default"
────╯
Error: ParserError
    ╭─[ :20:1 ]
    │
 20 │ }
    │ ┬
    │ ╰── unrecognised token '}', expected identifier, annotation, string, hexstring, address, number, rational, hexnumber, ";", "(", "[", Uint, Int, Bytes, "byte", "struct", "import", "contract", "pragma", "bool", "address", "string", "bytes", "interface", "library", "event", "enum", "type", "true", "false", "payable", "function", "mapping", "at", "abstract", "using", "leave", "switch", "case", "default"

This only happens in v1.2. Version v1.1 doesn't have this issue

Repository to reproduce: https://github.com/gnkz/forge-fmt-issue
Github action run that shows the error: https://github.com/gnkz/forge-fmt-issue/actions/runs/15324565761/job/43115719350

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-bugType: bugT-needs-triageType: this issue needs to be labelled

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions