Skip to content

Implementing interface method returning byref<'t> cannot just throw #5776

@marklam

Description

@marklam

For an interface method with a byref<'t> return, it's not possible to provide an implementation that just throws an exception

Repro steps

open System

type Ii<'T> =
    abstract GetSpan : int -> ReadOnlySpan<'T>

[<Struct>]
type X(value : int) =
    interface Ii<int> with
        member __.GetSpan n = ReadOnlySpan()

[<Struct>]
type Y(value : int) =
    interface Ii<int> with
        member __.GetSpan n = failwith "Nope"

Expected behavior

Compiles

Actual behavior

The line

member __.GetSpan n = failwith "Nope"

reports the error
FS0412 A type instantiation involves a byref type. This is not permitted by the rules of Common IL.

Known workarounds

Include an unreachable dummy return value

        member __.GetSpan n = failwith "Nope";  ReadOnlySpan()

Related information

Visual F# Tools 10.2 for F# 4.5 15.8.0.0. Commit Hash: 39fd7b8.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions