fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

#nowarn to be interpreted consistently in fsi

Open smoothdeveloper opened this issue 5 years ago • 1 comments

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?

smoothdeveloper avatar Nov 24 '20 03:11 smoothdeveloper

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)

abelbraaksma avatar May 22 '24 22:05 abelbraaksma