fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

No compile-time error for partial implementation of interface with static abstract members

Open brianrourkeboll opened this issue 2 months ago • 0 comments

There is no compile-time error if a type only partially implements an interface with static abstract members (IWSAM). If you try to use the partial implementation, a System.TypeLoadException is raised at runtime.

Repro steps

#nowarn "3535"

type IFace =
    static abstract P1 : int
    static abstract P2 : int

type T =
    interface IFace with
        static member P1 = 1

let inline p1<'T & #IFace> = 'T.P1

p1<T>

Runtime error:

Unhandled exception. System.TypeLoadException: Virtual static method 'get_P2' is not implemented on type 'T' from assembly 'ConsoleApp1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
   at <StartupCode$ConsoleApp1>.$Program.main@()

Expected behavior

There should be a compile-time error indicating that all abstract methods on the interface must be implemented.

Actual behavior

There is no compile-time error; there is an error at runtime instead.

Known workarounds

N/A

Related information

.NET 8/9 preview.

brianrourkeboll avatar May 11 '24 20:05 brianrourkeboll