-
Notifications
You must be signed in to change notification settings - Fork 830
Description
The release of F# 10 introduces to ability to mark an optional parameter as [<Struct>] to avoid unnecessary heap allocation. However, due to some flaw of the type checker, one now cannot directly pass in a voption to such a parameter.
Repro steps
Suppose there is a method with a [<Struct>] optional argument:
type Foo =
static member Bar([<Struct>] ?x: unit) = xNow if one pass in a voption, they gets an FS0001:
Foo.Bar(?x=ValueNone)
// error FS0001: This expression was expected to have type
// 'unit option'
// but here has type
// 'unit voption'Conversely, passing in an option does not work too:
Foo.Bar(?x=None)
// error FS0193: Type mismatch. Type
// “'a option”
// and type
// “unit voption” are incompatibleExpected behavior
The compiler should at least accept the case of voption into [<Struct>] optional parameter. Additionally, the compiler may apply implicit conversion between options and voptions to provide better backward compatiblity.
Actual behavior
It doesn't.
Known workarounds
Avoid explicit optional argument passing, and resort to pattern matching or something to decide whether the argument is to be passed in to the method.
Related information
- .NET SDK: .NET 10
Metadata
Metadata
Assignees
Labels
Type
Projects
Status