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

[MVUX] Code generation fails for generic types #2366

Open
kazo0 opened this issue Jun 19, 2024 · 2 comments
Open

[MVUX] Code generation fails for generic types #2366

kazo0 opened this issue Jun 19, 2024 · 2 comments
Labels
kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification.

Comments

@kazo0
Copy link
Contributor

kazo0 commented Jun 19, 2024

If I try and create a generic class and use it as a Feed property on my model, the code generation for the model fails with:

CSC : warning CS8785: Generator 'FeedsGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentException' with message 'The hintName 'mvuxtestapp.Presentation.Iterator.g.cs' contains an invalid character '<' at position 33. (Parameter 'hintName')'. [/Users/steve/src/TestApps/mvuxtestapp/mvuxtestapp/mvuxtestapp.csproj]
/Users/steve/src/TestApps/mvuxtestapp/mvuxtestapp/Presentation/MainModel.cs(21,81): warning CS8603: Possible null reference return. [/Users/steve/src/TestApps/mvuxtestapp/mvuxtestapp/mvuxtestapp.csproj]

My Model:

namespace mvuxtestapp.Presentation;

public partial record MainModel
{
    private INavigator _navigator;

    public MainModel(
        IStringLocalizer localizer,
        IOptions<AppConfig> appInfo,
        INavigator navigator)
    {
        _navigator = navigator;
        Title = "Main";
        Title += $" - {localizer["ApplicationName"]}";
        Title += $" - {appInfo?.Value?.Environment}";
    }

    public string? Title { get; }

    public IState<string> Name => State<string>.Value(this, () => string.Empty);
    public IState<Iterator<int>> Test => State<Iterator<int>>.Value(this, () => null);

    public async Task GoToSecond()
    {
        var name = await Name;
        await _navigator.NavigateViewModelAsync<SecondModel>(this, data: new Entity(name!));
    }

}

public record Iterator<T>(IImmutableList<T> Items)
{
	public int CurrentIndex { get; init; } = 0;
	public T CurrentItem => Items[CurrentIndex];
	public int Count => Items.Count;
	public bool CurrentIsLast => CurrentIndex == Items.Count - 1;
	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;
}

mvuxtestapp.zip

@kazo0 kazo0 added kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification. labels Jun 19, 2024
@kazo0
Copy link
Contributor Author

kazo0 commented Jun 19, 2024

fyi @dr1rrb / @Kunal22shah

This is causing us to use the hack as part of https://github.com/unoplatform/uno.chefs/pull/1181

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification.
Projects
None yet
Development

No branches or pull requests

2 participants