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

Invalid CS8602 calling base constructor when using primary constructors #68384

Closed
drewnoakes opened this issue May 30, 2023 · 0 comments · Fixed by #68441
Closed

Invalid CS8602 calling base constructor when using primary constructors #68384

drewnoakes opened this issue May 30, 2023 · 0 comments · Fixed by #68441
Assignees
Milestone

Comments

@drewnoakes
Copy link
Member

drewnoakes commented May 30, 2023

Version Used:

4.7.0-1.final

Steps to Reproduce:

#nullable enable

class B(string s)
{
    public string S { get; } = s;
}

class C(B b)
    : B(b.S)
//      ^ CS8602 dereference of a possibly null reference
{
    string T() => b.S; // removing this usage makes the diagnostic disappear
}

https://sharplab.io/#v2:EYLgtghglgdgPgYhgVwDaosVBTABNmTHAWACgyABAJlwCEAKCgRgAZcBnASjIG8zcBuCgGYhrXAGVcPXAHNsAFwDcuAL64AvByVlVZSjQDC9WrmDdSg3CDr1gAOgkWA9M6sCAerkMSAHADYWGgATbAAnbAAzcIIAYzwAe0jcCFwABwT2digsAE9cFHRcCOiImHjefkFmNgAVek5NAD4zRxVXYuwwBIA3WFlcBQALKHZcZHYIeVxIAGtsMeG8YKgpmEyFKFjcFcm0tOwIMN0yIA==

Diagnostic Id:

CS8602

Expected Behavior:

No diagnostic. The code that produces this diagnostic was fine before I invoked the "convert to primary constructor" fix.

Actual Behavior:

Incorrect diagnostic.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels May 30, 2023
@jcouv jcouv added New Language Feature - Nullable Reference Types Nullable Reference Types New Feature - Primary Constructors Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels May 31, 2023
@jcouv jcouv added this to the 17.7 milestone May 31, 2023
AlekseyTs added a commit to AlekseyTs/roslyn that referenced this issue Jun 5, 2023
@AlekseyTs AlekseyTs added the 4 - In Review A fix for the issue is submitted for review. label Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants