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

CascadingTypeParameter not passing down nullability #10201

Open
danielchalmers opened this issue Apr 2, 2024 · 2 comments
Open

CascadingTypeParameter not passing down nullability #10201

danielchalmers opened this issue Apr 2, 2024 · 2 comments
Assignees
Labels
area-blazor area-compiler Umbrella for all compiler issues feature request Large improvement request
Milestone

Comments

@danielchalmers
Copy link

Discussed in dotnet/aspnetcore#54332

Originally posted by danielchalmers March 3, 2024
I have a MudToggleGroup<System.Nullable<int>> but the children's types are the non-nullable MudToggleItem<int>.

<MudToggleGroup T="int?">
    <MudToggleItem Value="1" Text="Coffee (1)" />
    <MudToggleItem Value="2" Text="Tee (2)" />
    <MudToggleItem Value="3" Text="Water (3)" />
</MudToggleGroup>
@* MudToggleGroup.razor *@
@namespace MudBlazor
@attribute [CascadingTypeParameter(nameof(T))]
@inherits MudComponentBase
@typeparam T
@* MudToggleItem.razor *@
@namespace MudBlazor
@inherits MudComponentBase
@typeparam T

There are no other ancestors with a type param named T.

Any idea on how to pass down the nullability without manually casting them like Value="@((int?)3)"?

@javiercn
Copy link
Member

javiercn commented Apr 2, 2024

@danielchalmers thanks for contacting us.

I don't think there's a way to do it other than anotating the T in the @typeparam which I don't remember if it's possible. This will likely require compiler work to support it.

@javiercn javiercn transferred this issue from dotnet/aspnetcore Apr 2, 2024
@davidwengier davidwengier added the area-compiler Umbrella for all compiler issues label Apr 2, 2024
@chsienki chsienki self-assigned this Apr 4, 2024
@chsienki chsienki added the bug Something isn't working label Apr 4, 2024
@chsienki chsienki added this to the Backlog milestone Apr 4, 2024
@chsienki
Copy link
Contributor

chsienki commented Apr 4, 2024

Looks like the type inference would need to explicitly set the type param in the presence of CascadingTypeParam

            __builder.OpenComponent<global::BlazorApp42.Components.Pages.MudToggleGroup<int?>>(5);
            __builder.AddAttribute(6, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => {
                global::__Blazor.BlazorApp42.Components.Pages.Home.TypeInference.CreateMudToggleItem_0<int?>(__builder2, 7, 8, // <!-- THIS. Today we don't emit <int?> so can't infer the type. We would need to explicitly add it as a type param in this case.
#nullable restore
#line (10,27)-(10,31) "C:\Projects\scratch\BlazorApp42\BlazorApp42\Components\Pages\Home.razor"
null

#line default
#line hidden
#nullable disable
                , 9, "Coffee (1)");
                __builder2.AddMarkupContent(10, "\r\n    ");
                global::__Blazor.BlazorApp42.Components.Pages.Home.TypeInference.CreateMudToggleItem_1(__builder2, 11, 12, 
#nullable restore
#line (11,27)-(11,28) "C:\Projects\scratch\BlazorApp42\BlazorApp42\Components\Pages\Home.razor"
2

#line default
#line hidden
#nullable disable
                , 13, "Tee (2)");
                __builder2.AddMarkupContent(14, "\r\n    ");
                global::__Blazor.BlazorApp42.Components.Pages.Home.TypeInference.CreateMudToggleItem_2(__builder2, 15, 16, 
#nullable restore
#line (12,27)-(12,28) "C:\Projects\scratch\BlazorApp42\BlazorApp42\Components\Pages\Home.razor"
3

#line default
#line hidden
#nullable disable
                , 17, "Water (3)");
            }
            ));
            __builder.CloseComponent();

@chsienki chsienki added feature request Large improvement request and removed bug Something isn't working labels Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor area-compiler Umbrella for all compiler issues feature request Large improvement request
Projects
None yet
Development

No branches or pull requests

4 participants