Skip to content

Invalid CS8602 calling base constructor when using primary constructors #68384

@drewnoakes

Description

@drewnoakes

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions