dotnet / dotnet/fsharp

Incorrect indentation mixed with #if gives surprising results

Open
#1,564 2 comments 0 reactions 0 assignees View on GitHub
Area-Compiler-Syntax Bug Impact-Low
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

#### Please provide a succinct description of the issue.

From [this question on Stack Overflow](http://stackoverflow.com/questions/39581342/if-else-endif-breaking-f-script), given the script:

```
//error.fsx

#if INTERACTIVE
let msg = "Interactive"
#else
let msg = "Not Interactive"
#endif

let add x y =
x + y

printfn "%d" (add 1 2)
```

The output is: **error.fsx(12,15): error FS0039: The value or constructor 'add' is not defined**
#### Repro steps

Save the code given above (labeled as `error.fsx`) and run using fsi.exe version 4.0.
#### Expected behavior

Don't treat the `printfn` line as indented
#### Actual behavior

It seems that with the indentation, the F# parser actually parses the code as follows (from @tpetricek)

> ```
> let msg = "Interactive"
> let add x y =
> x + y
> printfn "%d" (add 1 2)
> ```
>
> The spacing before let msg causes the compiler to treat printfn as being indented too.
#### Known workarounds

Don't be a dumdum.
#### Related information

Running fsi.exe v4.0

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.