fsharp / fsharp/fslang-suggestions

Tracking suggestion: Misaligned methods

Open
#585 0 comments 4 reactions 0 assignees View on GitHub
approved-in-principle area: syntax
Dominant language
No language data
Stars
373
Forks
21
PR merge metrics
No merged PRs in 30d

Description

There is a proposal to adjust the syntax rules to give errors or warnings for misaligned methods

See https://github.com/Microsoft/visualfsharp/issues/1504, pasted below

## Case 1
#### Repro steps

Provide the steps required to reproduce the problem

Take this code:
![image](https://cloud.githubusercontent.com/assets/4236651/18087466/a583ed78-6eb5-11e6-9ec1-8cd3dc77d25a.png)
#### Expected behavior

It should complain at the declaration of `test 2`.
#### Actual behavior

It compiles without errors or warnings.

---
## Case 2

Now, this case isn't actually that bad. What had me and a colleague stumped for some time was the behaviour, when you add a loop to the method:

![image](https://cloud.githubusercontent.com/assets/4236651/18087546/137097dc-6eb6-11e6-9e75-75c6c994c6ac.png)

If I remove two spaces each from the method declaration, it compiles.

In our more complex example, there was an error `this value is not a function and can not be applied` in the middle of the method, but if you copied the whole code block into another method, it compiled. Removing the block also made the method compile.

#### Code

```fsharp
module Tests

open System.IO
open System.Xml.Linq
open System
open System.Xml
open System.Security.Cryptography
open Xunit

type FSharpTests() =
[]
member __.``test 1``() =
()

[]
member __.``test 2``() =
let folder = Path.Combine(__SOURCE_DIRECTORY__, @"..\..\Data")
let paths = [| Path.Combine(folder, "1")
Path.Combine(folder, "2") |]
ignore paths.Length
// for x in paths do ()
// ()
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the two F# reproductions in the issue and read the linked visualfsharp issue for additional context. Investigate how syntax rules handle the differently indented method declarations and the loop variant. Done means the first case produces the requested error or warning and the behavior of the second case is addressed consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
fsharp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.