Fsharp: Unsoundness issue in recursive class declarations

Created on 30 Nov 2017  路  4Comments  路  Source: dotnet/fsharp

Repro steps

Compiling and executing the code

type Foo() =
    static let test (t : 'T) : 'T list = 
        let b = new Bar<'T>(t)
        [b.Value]

    static member Test(t : int) = test t

and Bar<'T>(value : 'T) =
    member __.Value = value

printfn "%A" (Foo.Test 42)

Results in a segmentation fault. Peverify output:

[IL]: Error: [C:\Users\eirik.tsarpalis\Desktop\test.exe : Test+Foo::test[T]][offset 0x00000001][found (unboxed) 'T'][expected ref 'System.Object'] Unexpected type on the stack.
[IL]: Error: [C:\Users\eirik.tsarpalis\Desktop\test.exe : Test+Foo::test[T]][offset 0x00000017][found ref 'Microsoft.FSharp.Collections.FSharpList`1[System.Object]'][expected ref 'Microsoft.FSharp.Collections.FSharpList`1[T]'] Unexpected type on the stack.
2 Error(s) Verifying test.exe

Known workarounds

Place Bar<'T> declaration on top of Foo.

Related information

Windows 10, VS 15.4, Desktop CLR

Area-Compiler Severity-High bug

Most helpful comment

All 4 comments

It seems that the type checker is erroneously associating the two 'T variables in Bar and test. If I try to rename either of the two letters, a compiler warning will appear.

@eiriktsarpalis Thanks for this, I'll take a look

This has been merged and fixed

Was this page helpful?
0 / 5 - 0 ratings