Skip to content

Delegates are broken up around -> which leads to illegal code #2468

Closed

Description

@abelbraaksma

Issue created from fantomas-online

Code

type some_delegate = delegate of Func<int, int> * Guid * string * Func<Func<int, int>, int> -> Func<Func<int, int>, string, string>

Result

type some_delegate = delegate of Func<int, int> * Guid * string * Func<Func<int, int>, int> ->
    Func<Func<int, int>, string, string>

Problem description

In the example here I used some nonsense delegate just to illustrate the issue. It happens whenever the delegate definition is too wide. The result is non-compilable.

As a workaround I just place these definitions (I have a bunch of them) in a separate file and ignore it. I know delegates aren't really used that much in F# anyway.

Btw, tbh, I don't really know what a "best practice" format is for delegates, but I think the easiest fix would be to simply not format them at all. Alternatively, something like this works:

type some_delegate = delegate of 
                        Func<int, int> * Guid * string * Func<Func<int, int>, int> ->
                        Func<Func<int, int>, string, string>

Another way would be this:

type some_delegate = 
    delegate of 
       Func<int, int> * Guid * string * Func<Func<int, int>, int> ->
       Func<Func<int, int>, string, string>

Extra information

  • The formatted result breaks my code.
  • The formatted result gives compiler warnings errors.
  • I or my company would be willing to help fix this. (I'm a bit busy, but I'll try!)

Options

Fantomas master branch at 2022-08-31T07:53:05Z - 0981dfe

Default Fantomas configuration

Did you know that you can ignore files when formatting from fantomas-tool or the FAKE targets by using a .fantomasignore file?

Activity

  1. nojaf commented on Aug 31, 2022

    @nojaf
    Contributor

    Hello, thank you for the report.

    This might be a duplicate of #1514.
    You would want to go with

    type some_delegate = 
        delegate of 
            ...

    In order to avoid a vanity alignment.

    I believe the delegate body would play out correctly according to the other rules of function types here.

    The first part of this pointer, might already be enough in this case.

    Are you interested in submitting a PR?

  2. abelbraaksma commented on Aug 31, 2022

    @abelbraaksma
    MemberAuthor

    Sure. I was planning to do some OS work over the weekend, so I might try this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions