Skip to content

Make.Fs: a namespaced case with a record payload fails at run time (cast to Target) #10

Done

Description

@Mpdreamz

A nested union (a namespace) whose case carries a record payload shows correct help but fails when the target runs: Unable to cast object of type 'Status' to type 'Target'. A namespace case without a payload works, and so does a top-level case with a record.

Reproduce

Nullean.Make.Fs 0.27.1, .NET 11, run as a script.

#r "nuget: Nullean.Make.Fs, 0.27.1"
open Nullean.Make.Fs

type StatusOptions = { Json: bool }

[<RequireQualifiedAccess>]
type SnapTarget =
    | Status of StatusOptions
    | Review

type Target =
    | Hello
    | Snap of SnapTarget

let app = MakeApp<Target>("build", None)
app.Bind <| function
    | Hello -> target [] { printfn "hello" }
    | Snap (SnapTarget.Status o) -> target [] { printfn $"status json={o.Json}" }
    | Snap SnapTarget.Review -> target [] { printfn "review" }
app.RunAsync(fsi.CommandLineArgs |> Array.skip 1).GetAwaiter().GetResult() |> exit
$ ./build.fsx snap review
review

$ ./build.fsx snap status --json
[make] Target 'snap/status' failed: Unable to cast object of type 'Status' to type 'Target'.

snap status with no flag fails the same way. build snap --help and build snap status --help list the target and its --json option correctly.

Expected

snap status --json binds Json = true like test --filter x does at the top level, so a namespace can group targets that take options, for example snap accept <keys> --all, journeys live <site> --only x and site build.

Impact

The only workaround is to flatten each case to the top level (SnapStatus, which becomes snap-status), which loses the namespace in the help and in the generated mise task names (snap:status).

Activity

  1. transferred this issue fromnullean/arghon Nov 26, 2026
  2. Mpdreamz commented on Nov 26, 2026

    @Mpdreamz
    ContributorAuthor

    Still reproduces on Runna.Fs 0.2.0, the successor to Nullean.Make.Fs. This is the original script with the package and namespace swapped:

    #r "nuget: Runna.Fs, 0.2.0"
    open Nullean.Runna.Fs
    
    type StatusOptions = { Json: bool }
    
    [<RequireQualifiedAccess>]
    type SnapTarget =
        | Status of StatusOptions
        | Review
    
    type Target =
        | Hello
        | Snap of SnapTarget
    
    let app = RunnaApp<Target>("build", None)
    app.Bind <| function
        | Hello -> target [] { printfn "hello" }
        | Snap (SnapTarget.Status o) -> target [] { printfn $"status json={o.Json}" }
        | Snap SnapTarget.Review -> target [] { printfn "review" }
    app.RunAsync(fsi.CommandLineArgs |> Array.skip 1).GetAwaiter().GetResult() |> exit
    • dotnet fsi repro.fsx snap review runs and prints review.
    • dotnet fsi repro.fsx snap status --json and snap status both fail:
    System.InvalidCastException: Unable to cast object of type 'Status' to type 'Target'.
       at Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicFunctions.UnboxGeneric[T](Object source)
       at Nullean.Runna.Fs.FsGraphBuilder.FsTargetSource`1.Nullean.Runna.Execution.ITargetSource.Describe(TargetNode node, Object value)
       at Nullean.Runna.Execution.RunPlan.Builder.Visit(DepRef reference, Boolean isRoot, IReadOnlyList`1 waitFor)
       at Nullean.Runna.Execution.RunPlan.Build(IReadOnlyList`1 roots, ITargetSource source, PlanOptions options)
    

    So FsTargetSource.Describe unboxes the value of a nested case to the root Target type. Argh itself is not involved.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions