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

Potential relaxation of indentation requirements for type extensions #16988

Open
roboz0r opened this issue Apr 4, 2024 · 3 comments
Open

Potential relaxation of indentation requirements for type extensions #16988

roboz0r opened this issue Apr 4, 2024 · 3 comments

Comments

@roboz0r
Copy link

roboz0r commented Apr 4, 2024

Is your feature request related to a problem? Please describe.

In writing a type extension without remembering the typical syntax I arrived at something like:

type Id = Id of int

type Id 
    with static member Of(x) =
        if x < 1 then
            failwithf "Id must be less than %d" 1
        else
            Id x

Which gives the error:

Unexpected syntax or possible incorrect indentation: this token is offside of context started at position (5:10). Try indenting this further.
To continue using non-conforming indentation, pass the '--strict-indentation-' flag to the compiler, or set the language version to F# 7.

The error is clear enough and I was able to quickly fix the problem by indenting if beyond the s in static, however it seems like a situation where the indentation requirements could be loosened back to the with keyword.

Describe the solution you'd like

The above code could be made to compile without errors.

Describe alternatives you've considered

Another thing that could be done is moving the "Try indenting this further." part of the message to the start, as the proposed solution may not fit on the screen with inline errors (see attached screenshot)

I'm happy enough with the standard syntax:

type Id with
    static member Of(x) =
        if x < 1 then
            failwithf "Id must be less than %d" 1
        else
            Id x

Additional context

related: #11481

Add any other context or screenshots about the feature request here.

image

@vzarytovskii
Copy link
Member

I would assume this is "by design" with current rules, and this will need change in the lexer(?) spec. Maybe @auduchinok can chime in with more details.

@edgarfgp
Copy link
Contributor

edgarfgp commented Apr 6, 2024

Some discussion happened in fsharp/fslang-suggestions#1273

@abonie
Copy link
Member

abonie commented Apr 15, 2024

I think we would require a specific language suggestion here for this feature, to define what exactly is allowed/disallowed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: New
Development

No branches or pull requests

4 participants