dotnet / dotnet/fsharp

Potential relaxation of indentation requirements for type extensions

Open
#16,988 3 comments 0 reactions 0 assignees View on GitHub
Area-Compiler-Syntax Feature Request
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

**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:

```fs
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:

```fs
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](https://github.com/dotnet/fsharp/assets/9106604/45e82adc-3d3b-4467-a4a0-f345320f5a94)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.