Skip to content

Error: FSharp.Reflection: Microsoft.FSharp.Core.FSharpOption`1 is not an F# union type #4082

Description

@mlaily

Hello,

I encountered a surprising error while using Fable.Elmish.Browser custom Traces.console:

Unable to process the message: [*removed*] Error: Microsoft.FSharp.Core.FSharpOption`1 is not an F# union type
    getUnionCases Reflection.js:310
    getCaseName Program.fs:25
    ElmishDebug_getMsgNameAndFields Program.fs:47
    program_4 Program.fs:54
    update program.fs:92
    [...]

And indeed the type object has undefined cases.
Image

I verified in an F# interactive console and it does work as expected out of Fable:

> FSharp.Reflection.FSharpType.GetUnionCases(typeof<option<string>>);;
val it: Reflection.UnionCaseInfo array =
  [|FSharpOption`1.None
      {DeclaringType = Microsoft.FSharp.Core.FSharpOption`1[System.String];
       Name = "None";
       Tag = 0;};
    FSharpOption`1.Some
      {DeclaringType = Microsoft.FSharp.Core.FSharpOption`1[System.String];
       Name = "Some";
       Tag = 1;}|]

I added a unit test in Fable on my fork (see diff here) and it fails with the same error as above.

Image


Is it a known shortcoming of the reflection implementation in Fable that option types are not considered union cases?

Or is it a bug that needs fixing?

(I suspect it's a known shortcomings, because it seems too big to have been missed by inadvertence... but strangely I couldn't find an issue mentioning this?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions