DUCKY030: Union-first type is file-local
Package: Ducky (generator Ducky.Generators). Surface: build error on the name of the slice, effect group or union effect (ADR-0051, ADR-0052).
What happened
The generator registers the cases of a Slice<TState, TAction>, an EffectGroup<TAction> or an Effect<TAction> with a
union TAction by overriding RegisterCases in a generated partial declaration of the type, in a file of its own. A file type can't span two
files, so when the type, or a type it is nested in, is declared file, no generated declaration can extend it and no
case is registered. This replaces the DUCKY023 its registration would otherwise get.
For example, this code is reported:
using Ducky;
public sealed record Cart(int Count);
public sealed record AddItem(int Count);
public sealed record Clear;
public union CartAction(AddItem, Clear);
file sealed partial class CartSlice : Slice<Cart, CartAction>
{
protected override Cart Initial => new(0);
protected override Cart Reduce(Cart state, CartAction action) => action switch
{
AddItem a => new(state.Count + a.Count),
Clear => new(0),
};
}How to fix it
Remove the file modifier the message names; internal keeps the type out of other assemblies.