Skip to content

Commit

Permalink
Up
Browse files Browse the repository at this point in the history
  • Loading branch information
psfinaki committed Jan 7, 2025
1 parent 211b383 commit 414ab5d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/fsharp/language-reference/active-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ The attribute must be specified, because the use of a struct return is not infer

In F# 9, nullability related active patterns were added.

The first one is `| Null | NonNull x |`, which is a recommended way to handle possible nulls. In the following example, parameter `s` is inferred nullable via this active pattern usage:
The first one is `| Null | NonNull x |`, which is a recommended way to handle possible nulls. In the following example, parameter `s` is inferred nullable via this active pattern usage:

```fsharp
let len s =
Expand Down
25 changes: 25 additions & 0 deletions docs/fsharp/language-reference/compiler-directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,31 @@ let str = "Debugging!"
#endif
```

## NULLABLE directive

Starting with F# 9, you can enable nullable reference types in the project:

```xml
<Nullable>enable</Nullable>
```

This automatically sets `define:NULLABLE` directive to the build. It's useful while initially rolling out the feature, to conditionally change conflicting code by `#if NULLABLE` hash directives:

```fsharp
#if NULLABLE
let checkNonNull argName (arg: obj) =
match arg with
// nullness warning: the type 'obj' does not support 'null'
| null -> nullArg argName
| _ -> ()
#else
let checkNonNull argName (arg: obj) =
match arg with
| null -> nullArg argName
| _ -> ()
#endif
```

## Line Directives

When building, the compiler reports errors in F# code by referencing line numbers on which each error occurs. These line numbers start at 1 for the first line in a file. However, if you are generating F# source code from another tool, the line numbers in the generated code are generally not of interest, because the errors in the generated F# code most likely arise from another source. The `#line` directive provides a way for authors of tools that generate F# source code to pass information about the original line numbers and source files to the generated F# code.
Expand Down
1 change: 1 addition & 0 deletions docs/fsharp/language-reference/compiler-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The following table shows compiler options listed alphabetically. Some of the F#
|`--allsigs`|Generates a new (or regenerates an existing) signature file for each source file in the compilation. For more information about signature files, see [Signatures](signature-files.md).|
|`-a filename.fs`|Generates a library from the specified file. This option is a short form of `--target:library filename.fs`.|
|`--baseaddress:address`|Specifies the preferred base address at which to load a DLL.<br /><br />This compiler option is equivalent to the C# compiler option of the same name. For more information, see [&#47;baseaddress &#40;C&#35; Compiler Options&#41;](../../csharp/language-reference/compiler-options/advanced.md#baseaddress).|
|<code>--checknulls[+&#124;-]</code>|Enables [nullable reference types](./values/null-values.md#null-values-starting-with-f-9), added in F# 9.|
|`--codepage:id`|Specifies which code page to use during compilation if the required page isn't the current default code page for the system.<br /><br />This compiler option is equivalent to the C# compiler option of the same name. For more information, see [&#47;code pages &#40;C&#35; Compiler Options&#41;](../../csharp/language-reference/compiler-options/advanced.md#codepage).|
|`--consolecolors`|Specifies that errors and warnings use color-coded text on the console.|
|`--crossoptimize[+ or -]`|Enables or disables cross-module optimizations.|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Where lists appear in F# Interactive option arguments, list elements are separat
|------|-----------|
|**--**|Used to instruct F# Interactive to treat remaining arguments as command-line arguments to the F# program or script, which you can access in code by using the list **fsi.CommandLineArgs**.|
|**--checked**[**+**&#124;**-**]|Same as the **fsc.exe** compiler option. For more information, see [Compiler Options](compiler-options.md).|
|**--checknulls**[**+**&#124;**-**]|Same as the **fsc.exe** compiler option. For more information, see [Compiler Options](compiler-options.md).|
|**--codepage:&lt;int&gt;**|Same as the **fsc.exe** compiler option. For more information, see [Compiler Options](compiler-options.md).|
|**--consolecolors**[**+**&#124;**-**]|Outputs warning and error messages in color.|
|**--compilertool:&lt;extensionsfolder&gt;|Reference an assembly or directory containing a design time tool (Short form: -t).|
Expand Down
2 changes: 2 additions & 0 deletions docs/fsharp/language-reference/values/null-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ In F# 9, extra capabilities are added to the language to deal with reference typ
<Nullable>enable</Nullable>
```

This passes the `--checknulls+` [flag](../compiler-options.md) to the F# compiler and sets a `define:NULLABLE` [preprocessor directive](../compiler-directives.md#nullable-directive) for the build.

To explicitly opt-in into nullability, a type declaration has to be suffixed with the new syntax:

```fsharp
Expand Down

0 comments on commit 414ab5d

Please sign in to comment.