-
Notifications
You must be signed in to change notification settings - Fork 4k
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
AdditionalLocations for CS8618 in DiagnosticSuppressor #58073
Comments
A workaround that I can think of is to get the message using The compiler can make this easier if it used AdditionalLocations for reporting CS8618. It currently uses
|
@Youssef1313 thanks for your response.
Would you consider this a safe, robust workaround? For example, isn't it possible that this would fail in a different locale, since single quotes are used in the localized message in some way? Another workaround approach may be to use reflection to access CSDiagnostic.Arguments and get the property name from there - though that's also problematic. If this info can be added to AdditionalLocations (or any other way that allows this important context to be accessed), then we should be fine (this is a 7.0 release feature so we can wait for this to happen on the Roslyn side). |
@roji I think localization shouldn't be an issue. |
Thanks @Youssef1313! I'll wait for this to be done for 7.0 then and react on the EF Core side. |
@Youssef1313 thanks for the super quick turnaround! This indeed looks like what I need, once it's merged I'll make the necessary changes on the EF Core side and report how it goes. |
Thanks @Youssef1313 and @RikkiGibson! |
In EF Core, dotnet/efcore#21608 introduced a DiagnosticsSuppressor to suppress CS8618 (non-nullable property is uninitialized) in a specific safe scenario. In classes without a constructor, the CS8618 diagnostic is reported on the property itself, so the suppressor can look at that property and function correctly. If a constructor is defined, however, the diagnostic is reported on the constructor declaration instead of the property, and the suppressor needs some way to resolve the uninitialized property.
Diagnostic seems to have an AdditionalLocations property which looks right for this, but it's empty (because not populated for CS8618? Because it's a DiagnosticsSuppressor rather than a regular analyzer?).
Am I missing something? What would be the correct, safe way to figure out which non-nullable property is uninitialized from CS8618 in a DiagnosticsSuppressor?
Tracking issue on the EF Core side: dotnet/efcore#26879
The text was updated successfully, but these errors were encountered: