foundry icon indicating copy to clipboard operation
foundry copied to clipboard

`fmt` breaks on comment between variable declaration and value

Open 0xCLARITY opened this issue 3 years ago • 1 comments

Component

Forge

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

  • [X] Foundry
  • [X] Foundryup

What version of Foundry are you on?

forge 0.2.0 (4e11d1f 2022-08-24T00:11:17.970524Z)

What command(s) is the bug in?

forge fmt

Operating System

macOS (Apple Silicon)

Describe the bug

This variable declaration is valid Solidity and compiles correctly:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract BrokenFmt {
  uint256 public num =
    // This is a comment
    0;
}

However, forge fmt cannot parse it, and throws this error:

Failed to construct valid Solidity code for BrokenFmt.sol. Leaving source unchanged.
Debug info: [Diagnostic { loc: File(0, 143, 144), level: Error, ty: ParserError, message: "unrecognised token '0', expected \"!=\", \"%\", \"%=\", \"&\", \"&&\", \"&=\", \"(\", \")\", \"*\", \"**\", \"*=\", \"+\", \"++\", \"+=\", \",\", \"-\", \"--\", \"-=\", \".\", \"/\", \"/=\", \":\", \";\", \"<\", \"<<\", \"<<=\", \"<=\", \"=\", \"==\", \"=>\", \">\", \">=\", \">>\", \">>=\", \"?\", \"[\", \"]\", \"^\", \"^=\", \"calldata\", \"case\", \"constant\", \"days\", \"default\", \"error\", \"ether\", \"external\", \"gwei\", \"hours\", \"immutable\", \"indexed\", \"internal\", \"leave\", \"memory\", \"minutes\", \"override\", \"private\", \"public\", \"revert\", \"seconds\", \"storage\", \"switch\", \"weeks\", \"wei\", \"{\", \"|\", \"|=\", \"||\", \"}\", identifier", notes: [] }]

At the very least, it would be helpful to have a more helpful error message, but I believe forge fmt should be able to parse this given it compiles.

0xCLARITY avatar Aug 24 '22 16:08 0xCLARITY

yup - good catch, thanks!

gakonst avatar Aug 24 '22 17:08 gakonst

This appears to be resolved, so closing this

mds1 avatar Feb 28 '23 18:02 mds1