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

Incorrect nullability analysis for extension method with inference #78022

Open
jcouv opened this issue Apr 7, 2025 · 0 comments
Open

Incorrect nullability analysis for extension method with inference #78022

jcouv opened this issue Apr 7, 2025 · 0 comments
Labels
Area-Compilers Feature - Extension Everything The extension everything feature Feature - Nullable Reference Types Nullable Reference Types
Milestone

Comments

@jcouv
Copy link
Member

jcouv commented Apr 7, 2025

In the example below, the only argument for the extension method is oNull which may be null.
So oNull.Id has signature object? ().

The conversion to an explicit type works properly (warn on nullability issue with return type).
But in the function type scenario, it looks like var x isn't analyzed with that inferred type.

Also, the semantic model (GetSymbolInfo) has incorrect nullability for both member accesses.

This issue also impacts the semantic model for deconstructions.

This issue also impacts new extension members.

#nullable enable

object? oNull = null;
var x = oNull.Id;
x().ToString(); // Missing nullabiliy warning, indicating that the type inferred for `var` is incorrect

System.Func<object> y = oNull.Id; // correct warning on return type of delegate type

static class E
{
    public static T Id<T>(this T t) => t;
}
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Apr 7, 2025
@jcouv jcouv changed the title Missing warning on function type for extension method with inference Incorrect nullability analysis for extension method with inference Apr 7, 2025
@jcouv jcouv added the Feature - Extension Everything The extension everything feature label Apr 7, 2025
@jaredpar jaredpar added this to the Next milestone Apr 7, 2025
@jaredpar jaredpar removed the untriaged Issues and PRs which have not yet been triaged by a lead label Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature - Extension Everything The extension everything feature Feature - Nullable Reference Types Nullable Reference Types
Projects
None yet
Development

No branches or pull requests

2 participants