Fsharp: Recursive functions defined inside computation expressions fail after installing VS 15.5 preview 1

Created on 13 Oct 2017  路  4Comments  路  Source: dotnet/fsharp

After installing VS 15.5 preview 1, this fails:

[<EntryPoint>]
let main argv =
    let factorials =
        [ for x in 0..10 do
            let rec factorial x =
                match x with
                | 0 -> 1
                | x -> x * factorial(x - 1)
            yield factorial x
        ]

    for f in factorials do printf "%i" f

    0 // return an integer exit code

image

This happens even in VS 15.4 now.

Area-Compiler Severity-High bug regression

Most helpful comment

Fixed by undoing the fix, When we fix the fix it will all be fixed

All 4 comments

@dhwed Oh wow, that's a regression. The culprit will be https://github.com/Microsoft/visualfsharp/pull/3536

@cartermp I'll start working on a fix for this regression tomorrow

Workaround 1 - in this case compiling in "Release" mode makes NRE go away

Workaround 2 - lift the let rec out of the list/array/sequence expression, adding any captured variables as arguments

Fixed by undoing the fix, When we fix the fix it will all be fixed

Was this page helpful?
0 / 5 - 0 ratings