dotnet / dotnet/fsharp

while ... do: inconsistent handling of whitespace / indentation

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

Description

`while ... do` expressions handle whitespace / indentation in a manner that is not consistent with `if ... then ... else` expressions.
This is problematic when the test expression is lengthy and would be more clearly written using multiple lines, along the lines of:

``` fsharp
while
x > 10
&&
x < 20
do ...
```

**Repro steps**

Provide the steps required to reproduce the problem:

``` fsharp
let mutable x = 0
while
x < 10
do
x <- x + 1
```

**Expected behavior**

I would expect this to be valid syntax, in a fashion similar to

``` fsharp
if
x < 10
then
// do something
else
// do something
```

**Actual behavior**

`error FS0010: Incomplete structured construct at or before this point in expression`
`Missing 'do' in 'while' expression. Expected 'while do '.`

**Known workarounds**

Any indentation of `do` resolves the issue:

``` fsharp
let mutable x = 0
while
x < 10
do
x <- x + 1
```

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.