Skip to content

[RDG] Route handlers with the same parameters but differing nullability produce compiler warnings #46622

@captainsafia

Description

@captainsafia

At the moment, it's hard to use our strongly-typed overloads strategy to generate code that correctly handles two route handlers with the same parameters but differing nullability:

app.MapPost("/foo", (Todo todo) => ...);
app.MapPost("/bar", (Todo? todo) => ...);

We might consider generating two different strongly-typed overloads, one with the nullability annotations and one without:

MapPost(System.Action<Todo>);
MapPost(System.Action<Todo?>);

But overload resolution is not able to discern between the two delegate signatures and treats them as ambiguous overloads.

We can also emit only the overload that expects an NRT:

MapPost(System.Action<Todo?>);

But that presents a nullability warning to users (CS8622) when passing an overload to the delegate that does not expect an NRT.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-rdg

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions