Skip to content
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

result |> should be (ofCase <@ Ok @>) throws exception at runtime #198

Closed
BryanWilhite opened this issue Jan 28, 2022 · 3 comments
Closed

Comments

@BryanWilhite
Copy link

BryanWilhite commented Jan 28, 2022

Description

System.InvalidCastException
Unable to cast object of type 'Microsoft.FSharp.Core.FSharpResult`2[System.Tuple`2[System.Boolean,System.Text.Json.JsonElement],System.Text.Json.JsonException]' to type 'Microsoft.FSharp.Core.FSharpResult`2[System.Object,System.Object]'.
   at lambda_method25(Closure , Object )
   at FsUnit.Common.isOfCase@54.Invoke(a x)
   at NHamcrest.Core.CustomMatcher`1.Matches(T item)
   at Songhay.Dashboard.Bolero.Tests.SyndicationFeedTests.getAtomChannelTitle test(String elementName) 

Repro steps

    [<Theory>]
    [<InlineData(nameof GitHub)>]
    [<InlineData(nameof StackOverflow)>]
    let ``getAtomChannelTitle test`` elementName =
        let result: Result<(bool * JsonElement),JsonException> =
            appJsonDocument.RootElement
            |> SyndicationFeedUtility.getFeedElement elementName

        result |> should be (ofCase <@ Ok @>)

Related information

JetBrains Rider 2021.3.2
Build #RD-213.6461.51, built on December 22, 2021
Licensed to Bryan Wilhite
Subscription is active until August 12, 2022.
Runtime version: 11.0.13+7-b1751.21 amd64
VM: Dynamic Code Evolution 64-Bit Server VM by JetBrains s.r.o.
Linux 5.13.0-27-generic
.NET 6.0.1
GC: G1 Young Generation, G1 Old Generation
Memory: 1500M
Cores: 8
Registry:
    ide.new.project.model.index.case.sensitivity=true
    indexing.enable.entity.provider.based.indexing=false
    rdclient.asyncActions=false

Non-Bundled Plugins:
    com.settler.rider.specflow (1.10.2)
    com.intellij.plugins.vscodekeymap (213.5744.3)
    com.intellij.resharper.azure (3.50.0.1314-2021.3)

Current Desktop: ubuntu:GNOME
@sergey-tihon
Copy link
Member

This discussion should help #190 (comment)

As you error message say

Unable to cast object of type 'Microsoft.FSharp.Core.FSharpResult2[System.Tuple2[System.Boolean,System.Text.Json.JsonElement],System.Text.Json.JsonException]' to type 'Microsoft.FSharp.Core.FSharpResult`2[System.Object,System.Object]'.

result has type Microsoft.FSharp.Core.FSharpResult2[System.Tuple2[System.Boolean,System.Text.Json.JsonElement],System.Text.Json.JsonException]

Ok has type Microsoft.FSharp.Core.FSharpResult2[System.Object,System.Object](compiler was not able to infer generic params of Result type just fromOk`

So in runtime FsUnit see 2 objects with different types and they cannot be equal.

@CaptnCodr
Copy link
Member

CaptnCodr commented Jan 28, 2022

You may have to add further type declarations to your code.

Just try following:

result |> should be (ofCase <@ Result<(bool * JsonElement),JsonException>.Ok @>)

@BryanWilhite
Copy link
Author

excellent! many thanks @sergey-tihon and @CaptnCodr!

it is working as expected:

image

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

No branches or pull requests

3 participants