Here's a summary of what's new in F# in this Preview 5 release:
- Return-value attributes are preserved in more signatures
- Script files participate in parallel graph checking
- Command-line warning controls apply during option parsing
- F# 11 exception serialization preserves fields
- Bug fixes and other improvements
- Community contributors
Return-value attributes are now routed to the return metadata slot for more F# member shapes. Prefix [<return: ...>] attributes on class members are emitted to IL, no longer conflict with member-level attributes under AllowMultiple = false, and attributes on unparenthesized tuple return types are no longer dropped (dotnet/fsharp #19738, dotnet/fsharp #19714). Thank you @edgarfgp for these contributions!
open System
[<AttributeUsage(AttributeTargets.ReturnValue)>]
type ReturnDescriptionAttribute(text: string) =
inherit Attribute()
member _.Text = text
type Formatter =
[<return: ReturnDescription("normalized text")>]
member _.Normalize(value: string) = value.Trim()
static member Pair(value: string) : [<return: ReturnDescription("two values")>] string * string =
value, value.ToUpperInvariant()Graph-based type checking now records modules that are implicitly provided by script files. Projects that include .fsx files can stay on the parallel checking path instead of falling back to sequential checking up to the last script file (dotnet/fsharp #19649). Thank you @majocha for this contribution!
// A.fsx
let value = 41// B.fsx
#load "A.fsx"
let result = A.value + 1--nowarn and --warnaserror now apply to warnings produced while the compiler parses command-line options. Option warnings now follow the same suppression and escalation rules as warnings reported later in compilation (dotnet/fsharp #19776).
fsc --nowarn:75 --extraoptimizationloops:1 Program.fsWhen targeting frameworks where ISerializable exception serialization is available, F# 11 now emits serialization members for user-defined exceptions with fields. The generated members store and restore those fields through SerializationInfo, so round trips preserve the exception payload (dotnet/fsharp #19342, dotnet/fsharp #19746). This codegen is gated behind --langversion:11; earlier language versions keep the previous exception shape.
exception ParseFailed of line: int * message: string
let error = ParseFailed(12, "Unexpected token")
// On supported target frameworks, F# 11 emits serialization members
// that preserve both the line number and message fields.- Custom attribute arguments now handle more valid inputs: empty arrays of user-defined types compile, non-empty arrays of unencodable types report FS3887 instead of an internal compiler error, and optional primitive value-type attribute constructor parameters get the correct default values (dotnet/fsharp #19472, dotnet/fsharp #19484).
- Attributes in
namespace recandmodule recscopes now resolve opened namespaces before module attributes are checked (dotnet/fsharp #19502). - Nested inline SRTP functions with multiple overloads no longer hit internal error FS0073 during IL generation (dotnet/fsharp #19710). Thank you @gusty!
- Pattern matching inside
seq, list, and array comprehensions now narrows nullness correctly and avoids false-positive FS3261 warnings (dotnet/fsharp #19743). - Signature conformance now accepts an implementation member written as
member M(())for a signature member written asmember M: unit -> unitwhen the generated IL shape is the same (dotnet/fsharp #19615).
- Overload-resolution errors now underline the terminal method identifier instead of the entire object access and argument expression. Symbol-use ranges reported through name resolution now use the terminal identifier for the same cases (dotnet/fsharp #19505).
- Parser diagnostics in debug builds no longer expose internal parser-state details, and related parse errors have clearer wording (dotnet/fsharp #19730). Thank you @auduchinok!
usebindings no longer produce an internal compiler error when a C#-styleDisposeextension method is in scope alongsideIDisposable.Dispose(dotnet/fsharp #19568).
Thank you contributors! ❤️
F# updates: