fsharp / fslang-design

RFCs and docs related to the F# language design process, see https://github.com/fsharp/fslang-suggestions to submit ideas
512 stars 142 forks source link

Bug: Compilation error when multiple interface generic types are matched using `or`. #755

Closed GratianPlume closed 9 months ago

GratianPlume commented 9 months ago
   type IAH =
      abstract Foo: unit -> unit

   type IGM =
      abstract Foo: unit -> unit

   let inline foo (x: #IAH | x:#IGM) = x.Foo()

The above code compiles into:

.method public static 
    void foo<(FSharpLibrary.Test2/IGM, FSharpLibrary.Test2/IAH) a> (
        !!a x
    ) cil managed 
{
    // Method begins at RVA 0x2178
    // Header size: 12
    // Code size: 17 (0x11)
    .maxstack 3
    .locals init (
        [0] !!a
    )

    // ((IGM)(a)x).Foo();
    IL_0000: ldarg.0
    IL_0001: stloc.0
    // (no C# code)
    IL_0002: ldloca.s 0
    IL_0004: constrained. !!a
    IL_000a: callvirt instance void FSharpLibrary.Test2/IGM::Foo()
    // }
    IL_000f: nop
    IL_0010: ret
} // end of method Test2::foo

I think either it's not allowed to compile, or it's compiled into an optional interface