Skip to content

Plain ValueNone binding cannot be passed as inref #19608

@kerams

Description

@kerams

let ffff = ValueNone cannot be passed as inref without a type annotation or a mutable binding.

Repro steps

Provide the steps required to reproduce the problem:

https://sharplab.io/#v2:DYLgZgzgPsCmAuACAHogFATxIglgOwCdYwAeANQENgBXWAeQAd4cB7PE/eAPi4EpEAvOl4BYAFDi4SDMMHjECxFMRhBiSjVgBlFgFtYiAIzzFy3dXgUARnBWqhG2gDk2sEwuVgvax/Sat2Ti4AOl8XPDcxRSUEO28HKmdXd0QU1AAyMDTETKyoxQyvPOjCovFxIA

let x (y: inref<ValueOption<int>>) = ()

let y () =
    let f = ValueSome 1
    let mutable ff = ValueNone
    let fff = ValueOption<int>.ValueNone
    let ffff = ValueNone
    
    x &f
    x &ff
    x &fff
    x &ffff // <-- error

Expected behavior

Compiles.

Actual behavior

error FS3236: Cannot take the address of the value returned from the expression. Assign the returned value to a let-bound value before taking the address.

Known workarounds

Mutable binding, type annotatation.

Related information

Provide any related information (optional):

SDK 11.0.100-preview.3.26207.106

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-Checking-Byrefbyref, inref, outref, byref-like types, NativePtr, function pointers, struct semanticsBug

    Type

    No fields configured for Bug.

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions