dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.82k stars 773 forks source link

Improved error message: `use y = fixed x` does not compile inside computation expressions #5253

Open vasily-kirichenko opened 6 years ago

vasily-kirichenko commented 6 years ago

image

#nowarn "9"    

open System

type TestCaseBuilder() =
    member __.Using(disposable: IDisposable, f) =
      try
        f disposable
      finally
        match disposable with
        | null -> ()
        | disp -> disp.Dispose()

    member __.Combine(f1, f2) = f2(); f1
    member __.Zero() = ()
    member __.Delay f = f
    member __.Run f = f

let test = TestCaseBuilder()

[<EntryPoint>]
let main argv =
    let x = [|1|]
    use y = fixed x

    test {
      let x = [|1|]
      let y = fixed x
      use z = fixed x
      ()
    }
    |> ignore
    0
dsyme commented 3 years ago

I'm ok with this limitation, the interaction between the two features would almost always be unsound.

cartermp commented 3 years ago

This should be re-opened to track giving a useful diagnostic.

cartermp commented 3 years ago

Re-opening since there's an opportunity for a better diagnostic here, since the current error message is misleading