Skip to content

Generate Match and Switch with the parent's subclasses  #757

Closed

Description

@csillikd

The following example does not work: The best overload for 'Match' does not have a parameter named 'warning'

namespace Funcky.DiscriminatedUnion.Test;

public record ResultBase
{
    public sealed partial record Warning : ResultBase;
}

[DiscriminatedUnion]
public abstract partial record Result : ResultBase
{
    public sealed partial record Ok : Result;

    public sealed partial record Error : Result;
}

public static class ResultTest
{
    public static void ResultFn(Result result)
    {
        _ = result.Match(ok: _ => 0, warning: _ => 1, error: _ => 2);
    }
}

Activity

  1. tautropfli commented on Nov 7, 2023

    @tautropfli
    Contributor

    I feel like this is very much out of scope from the original goal of this source generator which is that it generates Match methods for hierarchies that are at the same time nested in one big class/record.

    If we were to implement this, we'd need to carefully consider the implementation of our incremental generator:

    • We are provided with the syntax node (in the example above that would be record Result { ... }, not the semantic model of the record Result
    • Getting the parent class is an operation on the semantic model, we get the semantic model in a second step after we're provided with the syntax node.
    • I don't know how we would tell Roslyn should also track the parent class' syntax node and rerun our generator for changes (This is important when you use the generator in your IDE).
  2. FreeApophis commented on Sep 24, 2026

    @FreeApophis
    Member

    Closed: see parent item.

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

    area: DiscriminatedUnionIssues for Funcky.DiscriminateUnionto discussThere are open points which need to be discussed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions