Skip to content

Type nativeptr<unit> isn't usable at all #4166

@realvictorprm

Description

@realvictorprm

Framework code which uses the type nativeptr<unit> isn't usable in F# because we cannot cast any nativeptr to nativeptr<unit>. Exact error is that unit isn't an unmanaged type.

I noticed this after trying to compile simple examples with the Span type from the System.Memory package. Because the C# equivalent of nativeptr<unit> is void* and nothing is wrong with a void pointer I thought reporting this here would be correct.

To have a senseful usage example look at this code (requires the System.Memory package!):

let someOperationWithSpan () =
    let data = NativePtr.stackalloc<byte>(256)
    let voidPtr = data |> NativePtr.toNativeInt |> NativePtr.ofNativeInt<unit> // This line doesn't compile
    let stackMemory = new Span<byte>(voidPtr, 256)
    // Do some stuff with the span!
    ()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions