Skip to content

Support F# 4.1 Result type #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jbrestan opened this issue May 9, 2017 · 8 comments
Closed

Support F# 4.1 Result type #131

jbrestan opened this issue May 9, 2017 · 8 comments

Comments

@jbrestan
Copy link

jbrestan commented May 9, 2017

Using Unquote 3.2.0 with FSharp.Core 4.4.1.0 (F# 4.1), the following test

[<Fact>]
let ThisWillFail () =
    let actual: Result<string, string> = Ok "foo"
    test <@ match actual with
            | Ok _ -> true
            | Error _ -> false @>

where Result is Microsoft.FSharp.Core.Result, fails with

System.NotSupportedException: Evaluation of quotation pattern AddressOf not supported: expression = AddressOf (ValueWithName (Ok "foo", actual))

I think this may be related to the fact that FSharpResult is a multi-case discriminated union struct. I've just started migrating to F# 4.1, so I am really mostly guessing here.

Using this equality check seems to work test <@ actual = Ok "foo" @>, but in my actual tests the value in Result cannot have equality, so I need to use match.

@stephen-swensen
Copy link
Contributor

@jbrestan super interesting, thanks for reporting!

I expect FSharpResult to be a pretty common type in the future of F#, especially within tests like here, so going to give this in high priority.

@jbrestan
Copy link
Author

jbrestan commented May 10, 2017

Thanks for quick response.

Let me know if you need more details to reproduce it - I've encountered this during relatively large project migration so it's possible something else is the root cause. When I use a custom Result type (just a regular DU with two cases) everything works though (with older 4.4.0.0 FSharp.Core as well as with the latest).

I'll try to look around your codebase to see if I'd be able to help

Update:
Not sure if I'll be able to look into it without doing similar migration as in my project - using FSharp.Core from NuGet instead of GAC, and updating it to the latest version (yours is currently 4.3.1.0, F# 3.1). I can do this to reproduce (and hopefully fix) the issue, but since this is a significant change in the whole project, I think its scope exceeds this fix/enhancement.

@dsyme
Copy link

dsyme commented May 11, 2017

I only looked at this very briefly, but it's vaguely possible there is a bug in F# quotations here - let me know if that's the case - (I hope not of course...)

@stephen-swensen
Copy link
Contributor

stephen-swensen commented May 12, 2017

Hi @dsyme -

Unquote has never supported AddressOf evaluation, so I am not surprised by the exception itself.

However, I am not sure if it is surprising that a quotation involving pattern matching on a struct union includes an AddressOf expression like we have here:

printfn "%A" 
    <@ match actual with
       | Ok _ -> true
       | Error _ -> false @>

IfThenElse (UnionCaseTest (AddressOf (ValueWithName (Ok "foo", actual)), Error),
        Value (false), Value (true))

Notably, I get a compiler error with the following similar pattern match on a struct tuple:

let actual = struct (0,0)
let code = 
    <@ match actual with
       | struct (0,0) -> true
       | _ -> false @>

Error FS0073 internal error: Unexpected expression shape

@dsyme
Copy link

dsyme commented May 23, 2017

@stephen-swensen Can you add a bug at http://github.com/Microsoft/visualfsharp please? We'd expect these to both work, thanks

@stephen-swensen
Copy link
Contributor

@dsyme done: dotnet/fsharp#3118

@stephen-swensen
Copy link
Contributor

Looks like this was fixed by dotnet/fsharp#3227 , closing

@dsyme
Copy link

dsyme commented Jul 14, 2017

@stephen-swensen Thanks for reporting the problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants