fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

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

Open auduchinok opened this issue 8 years ago • 4 comments

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

auduchinok avatar Oct 29 '17 18:10 auduchinok

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.

abelbraaksma avatar Oct 31 '17 02:10 abelbraaksma

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.

KevinRansom avatar Nov 02 '17 21:11 KevinRansom

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

abelbraaksma avatar Nov 03 '17 13:11 abelbraaksma

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

auduchinok avatar Nov 04 '17 16:11 auduchinok