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

#nowarn to be interpreted consistently in fsi #10535

Open smoothdeveloper opened 4 years ago

smoothdeveloper commented 4 years ago

with nowarn.fsx containing the following:

#nowarn "1104"
let ``@nowarn`` = 1

trying to invoke it with

dotnet fsi nowarn.fsx

getting

nowarn.fsx(2,5): warning FS1104: Identifiers containing '@' are reserved for use in F# code generation

If I try to do the same by pasting the contents in interactive session, it hides the warning.

The work around is to use --nowarn when invoking fsi.

Would it make sense to also hide the warnings in the first case?

abelbraaksma commented 6 months ago

Interesting. I just ran your test in debug session with the compiler and the warning is displayed before the hash-directive is even parsed. Something odd is going on here.

Note, related: #17209.

EDIT: it took me a moment to realize, but this appears to be warning-number specific. I.e., if the warning is thrown inside the lexer, it is not suppressed. However, if it occurs at a later state, it is properly suppressed.

#nowarn "1104"
#nowarn "25"

module Foo =
    let someFunc() =
        match 42 with // warning 25 is suppressed
        | 42 -> "yes"
        | 43 -> "no"

    let ``@nowarn`` = 1 // warning 1104 is not (because raised in lexer)