Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
abelbraaksma opened this issue Aug 22, 2017 · 4 comments
Assignees
Labels
Area-Diagnostics mistakes and possible improvements to diagnostics Feature Improvement
Milestone

Comments

@abelbraaksma
Copy link
Contributor

abelbraaksma commented Aug 22, 2017

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

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.

@dsyme dsyme added Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code. Area-Compiler Feature Request Feature Improvement and removed Feature Request Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code. labels Aug 22, 2017
@dsyme
Copy link
Contributor

dsyme commented Aug 29, 2017

@abelbraaksma I marked this as "feature improvement" - it should probably be "by design" since I don't think we count #if as a directive in this context. I'd need to check the language of the spec - but in any case we'd just adjust the language of the spec to clarify exactly which directives are/aren't taken into account where

@abelbraaksma
Copy link
Contributor Author

abelbraaksma commented Aug 30, 2017

@dsyme, I checked the language spec, this is what we say:

Compiler directives:

image

Conditional compilation, called lexical preprocessing directives

image

Line directives

image

Lightweight syntax (no name in the spec for it)

image

So, each is called directives (except for lightweight syntax).

Wouldn't the easiest fix be to simply improve the text? Since this error is raised in only one place, it would help by just changing it to:

FS0236 "Compiler directive '#nowarn' is ignored inside modules."

I know there's an ongoing effort in improving error messages, this could be a candidate ;). And since this error is never raised for any of the other directives, this is a safe change.

@dsyme
Copy link
Contributor

dsyme commented Aug 30, 2017

@abelbraaksma Yes, improving the message would be fine, thanks

@abelbraaksma
Copy link
Contributor Author

Self-assigning this, as I want to go over some preprocessor directives suggestions/proposals and this should be improved as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Diagnostics mistakes and possible improvements to diagnostics Feature Improvement
Projects
Archived in project
Development

No branches or pull requests

5 participants