Skip to content

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

Description

@abelbraaksma

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.

Activity

  1. added
    Impact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.
    and removed
    Impact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.
    on Aug 22, 2017
  2. dsyme commented on Aug 29, 2017

    @dsyme
    Contributor

    @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

  3. abelbraaksma commented on Aug 30, 2017

    @abelbraaksma
    ContributorAuthor

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

  4. dsyme commented on Aug 30, 2017

    @dsyme
    Contributor

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

  5. added this to the Unknown milestone on Aug 25, 2018
  6. added
    Area-Diagnosticsmistakes and possible improvements to diagnostics
    and removed on Mar 31, 2022
  7. self-assigned this
    on May 16, 2024
  8. abelbraaksma commented on May 16, 2024

    @abelbraaksma
    ContributorAuthor

    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

Metadata

Metadata

Assignees

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions