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

[CS8602] 'Dereference of a possibly null reference': False positive on property of generic interface #7402

Open
wsy opened this issue Sep 3, 2024 · 0 comments

Comments

@wsy
Copy link

wsy commented Sep 3, 2024

Analyzer

Diagnostic ID: CS8602: Dereference of a possibly null reference

Analyzer source

SDK: Built-in CA analyzers in .NET 8 SDK or later

Version: SDK 8.0.400

Describe the bug

Steps To Reproduce

Sample code

#nullable enable
public interface IData1<TId>
{
    TId Id { get; }
}

public interface IData2<TId>
{
    TId? Id { get; }
}

public class SampleClass<TId>
{
    private IQueryable<IData1<TId>> dataStorage1;
    private IQueryable<IData2<TId>> dataStorage2;
    public IData1<TId>? GetById1(TId id) => dataStorage1.SingleOrDefault(c => c.Id.Equals(id));
    public IData2<TId>? GetById2(TId id) => dataStorage2.SingleOrDefault(c => c.Id.Equals(id));
}

Expected behavior

Method GetById2 shall generate CS8602 because property Id has type TId?.
Method GetById1 shall not generate CS8602 because property Id has type TId.

Actual behavior

Both GetById1 and GetById2 will generate CS8602.
image

@wsy wsy changed the title [CS8602] False positive on property of generic interface: 'Dereference of a possibly null reference' [CS8602] 'Dereference of a possibly null reference': False positive on property of generic interface Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant