Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forge fmt incorrectly handles multi-line function pointer types in returns definitions #4080

Closed
2 tasks done
emo-eth opened this issue Jan 12, 2023 · 1 comment · Fixed by #6086
Closed
2 tasks done
Assignees
Labels
C-forge Command: forge Cmd-forge-fmt Command: forge fmt T-bug Type: bug

Comments

@emo-eth
Copy link
Contributor

emo-eth commented Jan 12, 2023

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (9256265 2023-01-12T00:04:39.480435Z)

What command(s) is the bug in?

fmt

Operating System

macOS (Apple Silicon)

Describe the bug

When running forge fmt on the following code, Forge will introduce two new tab-widths of spacing on the line(s) taken up by the function attributes (internal, pure, returns, etc) every time the command is run, even when it means the resulting line(s) will exceed the max line length specified by settings. This is true regardless of default or custom [fmt] settings.

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

contract ReturnFnFormat {
    function returnsFunction()
        internal
        pure
        returns (
            function() 
                    internal pure returns (uint256)
        )
    {}
}

It also will not correctly put a space between returns and the parentheses containing the type(s) returned by the returned function pointer, but will correctly add one to the function definition's returns attribute.

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

contract ReturnFnFormat {
    function returnsFunction()
        internal
        pure
        returns(
            function() 
            internal pure returns(uint256)
        )
    {}
}

becomes

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

contract ReturnFnFormat {
    function returnsFunction()
        internal
        pure
        returns (
            function() 
                    internal pure returns(uint256)
        )
    {}
}
@emo-eth emo-eth added the T-bug Type: bug label Jan 12, 2023
@rkrasiuk rkrasiuk added C-forge Command: forge Cmd-forge-fmt Command: forge fmt labels Jan 13, 2023
@rkrasiuk rkrasiuk self-assigned this Jan 13, 2023
@DJViau
Copy link
Contributor

DJViau commented Oct 23, 2023

We're still facing this issue, but I wanted to share two workarounds for people who come through here:

  1. Wrap the return in // forgefmt: disable-start and // forgefmt: disable-end
  2. Pack everything onto one line and then run forge fmt

The second option typically results in minimal or no changes, and ameliorates the problem of forge fmt adding a new tab width each time the command is run.

It'd be great to get a proper fix, though :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge Cmd-forge-fmt Command: forge fmt T-bug Type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants