Skip to content

ValueOption optional parameters cannot be passed as ValueOptions #19711

@nikonthethird

Description

@nikonthethird

Optional arguments using F# 10 ValueOption parameters cannot be passed using the question-mark syntax:
SomeMethodWithValueOptionOptionalParameter(?parameter = valueOptionValueHere) does not work.

Repro steps

type OptionalArguments () =
    member _.NoProblem (?number : int32) = ()
    member _.Problem ([<Struct>] ?number : int32) = ()

    member this.Test () =
        
        this.NoProblem 123                                // Works
        this.NoProblem (number = 123)                     // Works
        this.NoProblem (?number = None)                   // Works
        this.NoProblem (?number = Some 123)               // Works
        this.NoProblem (?number = Unchecked.defaultof<_>) // Works

        this.Problem 123                                  // Works
        this.Problem (number = 123)                       // Works
        this.Problem (?number = ValueNone)                // Does not work
        this.Problem (?number = ValueSome 123)            // Does not work
        this.Problem (?number = Unchecked.defaultof<_>)   // Does not work

        // Type constraint mismatch. The type ''a option' is not compatible with type 'int32 voption'

Expected behavior

All the cases above should work.

Actual behavior

The optional ValueOption parameter cannot be passed explicitly using the question-mark syntax.

Known workarounds

Remove the [<Struct>] attribute to transform the parameter into a reference-type optional parameter.

Related information

  • Ubuntu 24.04
  • .NET Runtime: Core 10.0.107 [/usr/lib/dotnet/sdk]
  • F# Interactive: Microsoft (R) F# Interactive version 14.0.107.0 for F# 10.0
  • Visual Studio Code 1.119.0
  • Ionide Plugin for Visual Studio Code: 7.31.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions