polyadic / funcky

Funcky is a Functional Library for C#
https://polyadic.github.io/funcky
Apache License 2.0
19 stars 3 forks source link

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

Open csillikd opened 11 months ago

csillikd commented 11 months ago

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);
    }
}
bash commented 11 months ago

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: