unoplatform / uno.extensions

Libraries to ease common developer tasks associated with building multi-platform mobile, desktop and web applications using Uno Platform or WinAppSDK.
https://platform.uno/
Other
71 stars 43 forks source link

[MVUX] Code generation fails to generate unique classes for generic types #2383

Open kazo0 opened 1 week ago

kazo0 commented 1 week ago

Given Iterator.cs:

public partial record Iterator<T>(IImmutableList<T> Items)
{
    public int CurrentIndex { get; init; } = 0;
    public T CurrentItem => Items[CurrentIndex];
    public int Count => Items.Count;
    public bool CanMoveNext => CurrentIndex < Items.Count - 1;
    public bool CanMovePrevious => CurrentIndex > 0;

    public Iterator<T> MoveNext()
        => CanMoveNext
            ? this with { CurrentIndex = CurrentIndex + 1 }
            : this;

    public Iterator<T> MovePrevious()
        => CanMovePrevious
            ? this with { CurrentIndex = CurrentIndex - 1 }
            : this;
}

And the following Model code:

public partial record MainModel
{
    public MainModel()
    {
    }

    public IState<Iterator<int>> Ints => State<Iterator<int>>.Value(this, () => new Iterator<int>(Enumerable.Range(0, 3).ToImmutableList()));
    public IState<Iterator<string>> Strings => State<Iterator<string>>.Value(this, () => new Iterator<string>(new string[] { "A", "B", "C" }.ToImmutableList()));
}

The following errors occur at compile time:

1>X:\src\TestApps\UnoApp51\UnoApp51\obj\Debug\net8.0-windows10.0.19041\intermediatexaml\Uno.Extensions.Reactive.Generator\Uno.Extensions.Reactive.Generator.FeedsGenerator\UnoApp51.Models.Iteratorstring.g.cs(16,22,16,38): error CS0101: The namespace 'UnoApp51.Models' already contains a definition for 'BindableIterator' 1>X:\src\TestApps\UnoApp51\UnoApp51\obj\Debug\net8.0-windows10.0.19041\intermediatexaml\Uno.Extensions.Reactive.Generator\Uno.Extensions.Reactive.Generator.FeedsGenerator\UnoApp51.Models.Iteratorstring.g.cs(15,3,15,57): error CS0579: Duplicate 'global::System.CodeDom.Compiler.GeneratedCodeAttribute' attribute 1>X:\src\TestApps\UnoApp51\UnoApp51\obj\Debug\net8.0-windows10.0.19041\intermediatexaml\Uno.Extensions.Reactive.Generator\Uno.Extensions.Reactive.Generator.FeedsGenerator\UnoApp51.Models.Iteratorint.g.cs(16,22,16,38): error CS0263: Partial declarations of 'BindableIterator' must not specify different base classes 1>X:\src\TestApps\UnoApp51\UnoApp51\obj\Debug\net8.0-windows10.0.19041\intermediatexaml\Uno.Extensions.Reactive.Generator\Uno.Extensions.Reactive.Generator.FeedsGenerator\UnoApp51.Models.Iteratorstring.g.cs(54,51,54,64): error CS0111: Type 'BindableIterator' already defines a member called 'CreateDefault' with the same parameter types

The classes that are generated are:

Iterator_int_g.cs:

public sealed class BindableIterator : global::Uno.Extensions.Reactive.Bindings.Bindable<UnoApp51.Models.Iterator<int>>

Iterator_string_g.cs:

public sealed class BindableIterator : global::Uno.Extensions.Reactive.Bindings.Bindable<UnoApp51.Models.Iterator<string>>

UnoApp51.zip

kazo0 commented 1 week ago

Related: https://github.com/unoplatform/uno.extensions/issues/2366

cc: @dr1rrb