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

Error when using BeOfCase on a struct discriminated union with shared fields #10

Closed
Numpsy opened this issue Dec 8, 2024 · 3 comments
Closed

Comments

@Numpsy
Copy link
Contributor

Numpsy commented Dec 8, 2024

Hi,

I was having a go at making some struct discriminated unions use shared/unnamed fields as described at https://learn.microsoft.com/en-us/dotnet/fsharp/whats-new/fsharp-9#field-sharing-for-struct-discriminated-unions in .NET 9 and hit an error in my unit tests.

Say I have a discriminated union like

    [<Struct>]
    type MyStructDu =
        | Field1 of string
        | Field2 of string

If I have a unit test on the first case like

    [<Fact>]
    let ``Struct DU case one`` () =
        let f1 = Field1 "F1"
        f1.Should().BeOfCase(Field1)

then it works ok, but for the second case, e.g

    [<Fact>]
    let ``Struct DU case two`` () =
        let f2 = Field2 "F2"
        f2.Should().BeOfCase(Field2)

Then i get

System.ArgumentException : This is not a valid tuple type for the F# reflection library. (Parameter 'types')
FSharpType.MakeTupleType(Type[] types) line 1148
[email protected](UnionCaseInfo unionCaseInfo) line 61
[email protected](a delegateArg0)
ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
[email protected](a a) line 32
MakeCaseTupleTypeCached.Static(UnionCaseInfo unionCaseInfo) line 79
[email protected](FSharpExpr expr) line 41
UnionAssertions.BeOfCase[a,b](Testable`1 t, FSharpExpr`1 caseConstructor, FSharpOption`1 because) line 47
BeOfCase.Struct DU case two() line 36
@cmeeren
Copy link
Owner

cmeeren commented Dec 9, 2024

Thanks for the report. Seems to be an upstream issue. I created dotnet/fsharp#18121.

@Numpsy
Copy link
Contributor Author

Numpsy commented Dec 9, 2024

Thanks

@cmeeren
Copy link
Owner

cmeeren commented Dec 10, 2024

Workaround here: dotnet/fsharp#18121 (comment)

Closing as it's an upstream issue.

@cmeeren cmeeren closed this as not planned Won't fix, can't repro, duplicate, stale Dec 10, 2024
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

2 participants