fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

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

Open abelbraaksma opened this issue 8 years ago • 4 comments

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.

abelbraaksma avatar Aug 22 '17 19:08 abelbraaksma

@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

dsyme avatar Aug 29 '17 13:08 dsyme

@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.

abelbraaksma avatar Aug 30 '17 03:08 abelbraaksma

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

dsyme avatar Aug 30 '17 11:08 dsyme

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

abelbraaksma avatar May 16 '24 18:05 abelbraaksma