dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.94k stars 788 forks source link

No indentation warning is given when a hash directive is used inside a nested module #3841

Open auduchinok opened 7 years ago

auduchinok commented 7 years ago

Consider File.fsx:

// implicit top-level module File

let x = 42

module Nested =
    // File.Nested.foo
    let foo = 123

#load "OtherFile.fsx"

    // Looks like File.Nested.bar, but is actually File.bar due to the use of #load.
    // Unlike conditional hash directives it terminates declarations/expressions,
    // which may be not very obvious to users.

    // I suppose, being in the outer module it should have the same indentation
    // as x and Nested module, however no indentation warning/error is given.

    // Looks like it also adds another context in the LexFilter,
    // which in turn makes next expressions indented incorrectly.
    let bar = foo // foo is unresolved

let y = x // incorrect indentation
abelbraaksma commented 7 years ago

Related to (but not the same) #3486 and #3487.

I think that indentation is ignored because # lines are typically a type of compiler directive and as such not part of the indentation rules. My guess is, this is by design.

KevinRansom commented 7 years ago

I think is just a bug:

The compiler is fine with:

module Nested =
    // File.Nested.foo
    let foo = 123

#if SOMEDIRECTIVE
#endif

    // looks like File.Nested.bar, but is actually File.bar
    // No indentation warning given and foo is unresolved
    let bar = foo

We probably just need to make sure that FSI only directives work correctly here.

abelbraaksma commented 7 years ago

@auduchinok, my apologies, I misunderstood, as I focused on the text and title and missed the comments in the code.

Could you perhaps update the original text with a complete repro (this module is currently not nested) and explain the issue in the text to forego such misunderstandings?

auduchinok commented 7 years ago

@abelbraaksma I've updated the code repro and added more clarification in the comments there.