Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
csillikd opened this issue Nov 6, 2023 · 1 comment
Open

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

csillikd opened this issue Nov 6, 2023 · 1 comment
Labels
area: DiscriminatedUnion Issues for Funcky.DiscriminateUnion

Comments

@csillikd
Copy link

csillikd commented Nov 6, 2023

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
Copy link
Member

bash commented Nov 7, 2023

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).

@bash bash added the area: DiscriminatedUnion Issues for Funcky.DiscriminateUnion label Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: DiscriminatedUnion Issues for Funcky.DiscriminateUnion
Projects
None yet
Development

No branches or pull requests

2 participants