Skip to content

FSharpValue.GetUnionFields returns empty array for non-first cases of struct unions with shared fields #18121

@cmeeren

Description

@cmeeren

In F# 9, FSharpValue.GetUnionFields only returns fields for the first case of struct unions with shared fields.

Repro: Repro.zip

open Microsoft.FSharp.Reflection

[<Struct>]
type MySharedStructDu =
    | A of int64
    | B of int64

for value in [A 1L; B 2L] do
    let caseInfo, inner = FSharpValue.GetUnionFields(value, typeof<MySharedStructDu>)
    printfn $"Inner value for case %s{caseInfo.Name} is %A{inner}"

Expected behavior

Inner value for case A is [|1L|]
Inner value for case B is [|2L|]

Actual behavior

Inner value for case A is [|1L|]
Inner value for case B is [||]

Known workarounds

I don't know of any, though to be fair I haven't looked for any either.

Metadata

Metadata

Assignees

Labels

Area-Compiler-CodeGenIlxGen, ilwrite and things at the backendBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.Regression

Type

Projects

Status

New

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions