You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/fsharp/language-reference/compiler-directives.md
+24-16Lines changed: 24 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,39 +19,45 @@ The following table lists the preprocessor directives that are available in F#.
19
19
20
20
|Directive|Description|
21
21
|---------|-----------|
22
-
|`#if`*symbol*|Supports conditional compilation. Code in the section after the `#if` is included if the *symbol* is defined. The symbol can also be negated with `!`.|
23
-
|`#else`|Supports conditional compilation. Marks a section of code to include if the symbol used with the previous `#if`is not defined.|
22
+
|`#if`*if-expression*|Supports conditional compilation. Code in the section after the `#if` is included if the *if-eyxpression* evaluates to `defined` (see below).|
23
+
|`#else`|Supports conditional compilation. Marks a section of code to include if the symbol used with the previous `#if`does not evaluate to `defined`.|
24
24
|`#endif`|Supports conditional compilation. Marks the end of a conditional section of code.|
25
25
|`#`[line]*int*,<br/>`#`[line]*int**string*,<br/>`#`[line]*int**verbatim-string*|Indicates the original source code line and file name, for debugging. This feature is provided for tools that generate F# source code.|
26
-
|`#nowarn`*warningcode*|Disables a compiler warning or warnings. To disable multiple warning numbers on the same line, separate each string by a space. <br/> For example: `#nowarn 9 42`|
26
+
|`#nowarn`*warningcode*|Disables a compiler warning or warnings. To disable multiple warning numbers on the same line, separate each string by a space. <br/> For example: `#nowarn 9 42`<br/> The warning is disabled until eof or until a `#warnon` directive for that same warning number is foud.|
27
+
|`#warnon`*warningcode*|Enables a compiler warning (or warnings) that was disabled by a compiler option or by a `#nowarn` directive..<br/> The warning is enabled until eof or until a `#nowarn` directive for that same warning number is found.|
27
28
28
-
The effect of disabling a warning applies to the entire file, including portions of the file that precede the directive.|
29
29
30
30
## Conditional Compilation Directives
31
31
32
32
Code that is deactivated by one of these directives appears dimmed in the Visual Studio Code Editor.
33
33
34
-
> [!NOTE]
35
-
> The behavior of the conditional compilation directives is not the same as it is in other languages. For example, you cannot use Boolean expressions involving symbols, and `true` and `false` have no special meaning. Symbols that you use in the `if` directive must be defined by the command line or in the project settings; there is no `define` preprocessor directive.
36
-
37
34
The following code illustrates the use of the `#if`, `#else`, and `#endif` directives. In this example, the code contains two versions of the definition of `function1`. When `VERSION1` is defined by using the [-define compiler option](./compiler-options.md), the code between the `#if` directive and the `#else` directive is activated. Otherwise, the code between `#else` and `#endif` is activated.
There is no `#define` preprocessor directive in F#. You must use the compiler option or project settings to define the symbols used by the `#if` directive.
42
-
43
-
Conditional compilation directives can be nested. Indentation is not significant for preprocessor directives.
44
-
45
-
You can also negate a symbol with `!`. In this example, a string's value is something only when _not_ debugging:
38
+
The `#if` directive also accepts logical expressions:
|`if-expr1 \|\| if-expr2`|`defined` if `if-expr1` or `if-expr2` is `defined`. |
50
+
|`if-expr1 && if-expr2`|`defined` if `if-expr1` and `if-expr2` are `defined`. |
51
+
|`!if-expr1`|`defined` if `if-expr1` is not `defined`. |
52
+
|`( if-expr1 )`| defined if `if-expr1` is defined. |
53
+
|`symbol`|`defined` if it is flagged as defined by the `-define` compiler option. |
54
+
55
+
The logical operators have the usual logical precedence.
56
+
57
+
There is no `#define` preprocessor directive in F#. You must use the compiler option or project settings to define the symbols used by the `#if` directive.
58
+
59
+
Conditional compilation directives can be nested. Indentation is not significant for preprocessor directives.
60
+
55
61
## NULLABLE directive
56
62
57
63
Starting with F# 9, you can enable nullable reference types in the project:
@@ -84,6 +90,8 @@ When you use the `#line` directive, file names must be enclosed in quotation mar
84
90
85
91
These tokens indicate that the F# code generated at this location is derived from some constructs at or near line `25` in `Script1`.
86
92
93
+
Note that `#line` directives do not influence the behavior of `#nowarn` / `#warnon`. These two directives always relate the the file that is being compiled.
0 commit comments