fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

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

Open vasily-kirichenko opened this issue 7 years ago • 3 comments

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

vasily-kirichenko avatar Jun 29 '18 08:06 vasily-kirichenko

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

dsyme avatar Aug 26 '20 13:08 dsyme

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

cartermp avatar Aug 26 '20 14:08 cartermp

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

cartermp avatar Aug 26 '20 15:08 cartermp