Ming-Tang
Ming-Tang

Reputation: 17661

F# Suppress Warnings

Sometimes I get annoying pattern matching and indent warnings when compiling F#. Is there a way to disable warnings? I'm pretty OCD over warnings.

Upvotes: 13

Views: 4250

Answers (3)

Richard
Richard

Reputation: 109130

As well as compiler command line and the project files, warnings can be supressed on a file basis (no option to just turn off for part of a file) use

#nowarn n

where n is the warning number (without the "FS" prefix. Multiple numbers can be listed:

#nowarn 3261 0010

See Preprocessor Directives,

Upvotes: 1

Brian
Brian

Reputation: 118895

In case you forget, you can type

let rec x = lazy(x.Value)

and get the warning

This and other recursive references to the object(s) being defined will be checked for initialization-soundness at runtime through the use of a delayed reference. This is because you are defining one or more recursive objects, rather than recursive functions. This warning may be suppressed by using '#nowarn "40"' or '--nowarn:40'.

which shows that you can use either the compiler flag --nowarn on the command-line, or use the hash-directive #nowarn in your code. The warning number for each warning will be part of the build output (the Visual Studio error list does not display the numbers, so if in VS, build and then inspect the build output). Also, if inside VS, you can go to the project properties page, "Build" tab, and use the "warning level" selector and "suppress warnings" field (a semicolon-delimited list of numbers) to control which warnings are diplayed via the VS UI.

(BTW, I believe #nowarn only turns off the warning in the current file, whereas --nowarn turns it off for the entire project being compiled.)

Upvotes: 13

NullUserException
NullUserException

Reputation: 85478

See: Compiler Options (F#)

--nowarn:<int-list>:

Disable specific warnings listed by number. Separate each warning number by a comma. You can discover the warning number for any warning from the compilation output.

This compiler option is equivalent to the C# compiler option of the same name. For more information, see /nowarn (C# Compiler Options).

Upvotes: 4

Related Questions