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

Blazor: inherits typeparam from another property "the type t must be a reference type in order to use it as a parameter" #11505

Open
itarsonmg opened this issue Feb 18, 2025 · 1 comment · May be fixed by #11530
Assignees
Labels
area-compiler Umbrella for all compiler issues
Milestone

Comments

@itarsonmg
Copy link

itarsonmg commented Feb 18, 2025

the example:

MyComponent.razor

@inherits ITComponentBase
@typeparam T

MyComponent.razor.cs

[CascadingTypeParameter(nameof(T))]
public partial class MyComponent<T> : ComponentBase 
{
    [Parameter]
    public MyQueryCommand<T> QueryCommand { get; set; } = default!;
}

public class MyQueryCommand<T>  
{

}

Page.razor

<MyComponent QueryCommand="new MyQueryCommand<AuthUser>()">
    
</MyComponent>

thats works perfect, but when I put a restriction in paramtype T, fails

MyComponent.razor.cs

[CascadingTypeParameter(nameof(T))]
public partial class MyComponent<T> : ComponentBase where T : IDomain
{
    [Parameter]
    public MyQueryCommand<T> QueryCommand { get; set; } = default!;
}

public class MyQueryCommand<T>  where T : IDomain
{

}

The sourceGenerator: error CS0314: El tipo 'T' no se puede usar como parámetro de tipo 'T' en el tipo o método genérico 'MyQueryCommand<T>'. No hay conversión boxing ni conversión de parámetro de tipo de 'T' a 'ITProject.Domain.IDomain'.

Page.razor.g.cs

        public static void CreateMyComponent_0<T>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, int __seq0, global::ITProject.Components.MyQueryCommand<T> __arg0)
            where T : global::ITProject.Domain.IDomain
        {
              ....................
        }

        public static void CreateMyComponent_0_CaptureParameters<T>(global::ITProject.Components.MyQueryCommand<T> __arg0, out global::ITProject.Components.MyQueryCommand<T> __arg0_out)
        {
            __arg0_out = __arg0;
        }

if I put a restriction in CreateMyComponent_0_CaptureParameters<T> same as it is in CreateMyComponent_0<T> all works

public static void CreateMyComponent_0_CaptureParameters<T>(global::ITProject.Components.MyQueryCommand<T> __arg0, out global::ITProject.Components.MyQueryCommand<T> __arg0_out)
where T : global::ITProject.Domain.IDomain
        {
            __arg0_out = __arg0;
        }
@davidwengier davidwengier added the area-compiler Umbrella for all compiler issues label Feb 18, 2025
@chsienki
Copy link
Member

This seems like something is up with our generic inference generation code. @jjonescz Can you take a look please?

@chsienki chsienki added this to the 2025-03 March milestone Feb 20, 2025
@jjonescz jjonescz linked a pull request Feb 21, 2025 that will close this issue
@jjonescz jjonescz self-assigned this Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-compiler Umbrella for all compiler issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants