dotnet / dotnet/fsharp

FS0236 "Directives inside modules are ignored" is incomplete and gives the wrong impression, directives inside modules are often allowed

Open
#3,486 4 comments 0 reactions 1 assignee Claimed by @abelbraaksma View on GitHub
Area-Diagnostics Feature Improvement
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

When you use a compiler directive, specifically `#nowarn`, inside a module, the message is "Directives inside modules are ignored". This message is incomplete and it takes some experimenting to find out its statement is usually not true.

## Repro steps

Take the following code:

```
module XBar =
#nowarn "test"

#if FALSE
module other =
let x = 12
#endif
```

This will show a warning for the first directive, but not the second:

![image](https://user-images.githubusercontent.com/16015770/29583048-19c72e92-877f-11e7-8ec4-bf5df92d67dd.png)

## Expected behavior

The warning should be more specific, I think it essentially only applies to `#nowarn` directives?

## Actual behavior

Regardless of the warning, the directive `#if` is obeyed, as is `#line` and perhaps others (but `#nowarn` is not, but this is a known limitation and by design).

## Known workarounds

Just learn to not be too alarmed by this all-too-generic warning :).

## Related information

This behavior can be seen on all versions of F# and VS, at least back to VS2015 and F# 4.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.