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

Missing nullability warnings for semi-autoproperties #76487

Open
TessenR opened this issue Dec 18, 2024 · 0 comments
Open

Missing nullability warnings for semi-autoproperties #76487

TessenR opened this issue Dec 18, 2024 · 0 comments
Labels
Area-Compilers Feature - Field Keyword untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@TessenR
Copy link

TessenR commented Dec 18, 2024

Version Used:

Branch main (17 Dec 2024)
Latest commit [f9ccce0](https://github.com/dotnet/roslyn/commit/f9ccce030d8fdcc2ea095e095b71316d243c5b35) by Phil Allen:
Update PublishData.json (#76471)

Steps to Reproduce:

Compile and run the following code (sharplab.io)

using System;
using System.Diagnostics.CodeAnalysis;
#nullable enable

var p = new C().Prop;
Console.WriteLine(p.Length);

class C
{
  [NotNull]
  public string? Prop
  {
    get;
    set => field = value ?? string.Empty;
  } = null;
}

Expected Behavior:
A warning is emitted for get; accessor that returns a possibly nullable field value as a result of a non-nullable property

Actual Behavior:
No warnings at all in the program above. It crashes with a NullReferenceException at runtime

Notes:
If you explicitly implement get; with the equivalent get => field; you get the correct CS8603: Possible null reference return. warning

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature - Field Keyword untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

2 participants