Skip to content

Blazor typeparam constraints causing compilation error CS0449 #7098

@xiety

Description

@xiety

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Problem looks like the closed dotnet/aspnetcore#38479, dotnet/aspnetcore#38041 and dotnet/razor-compiler#272, but dotnet/razor-compiler#44 doesn't fix it in the latest 7.0.100-rc.1.22363.3

Generated code with constraints in wrong order:

where T : global::System.IComparable, class

Produces compilation error:

CS0449	The 'class', 'struct', 'unmanaged', 'notnull', and 'default' constraints cannot be combined or duplicated, and must be specified first in the constraints list.

Expected Behavior

Code is generated without errors:

where T : class, global::System.IComparable

Steps To Reproduce

App.razor

<MyComponent Parameter="1" />

MyComponent.razor

@typeparam T where T : class, IComparable

@code
{
    [Parameter]
    public T Parameter { get; set; } = default!;
}

Exceptions (if any)

No response

.NET Version

7.0.100-rc.1.22363.3

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-compilerUmbrella for all compiler issues

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions