-
Notifications
You must be signed in to change notification settings - Fork 463
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
PreviewFeatures - Handle an error case where GetOverriddenMembers() returns null for an indexer #5596
Conversation
It's not quite clear why the type is marked In particular, Roslyn has this logic for // Has to be metadata virtual and cannot be a destructor.
// Must either lack the newslot flag or be an explicit override (i.e. via the MethodImpl table).
//
// The IsExplicitClassOverride case is based on LangImporter::DefineMethodImplementations in the native compiler.
// ECMA-335
// 10.3.1 Introducing a virtual method
// If the definition is not marked newslot, the definition creates a new virtual method only
// if there is not virtual method of the same name and signature inherited from a base class.
//
// This means that a virtual method without NewSlot flag in a type that doesn't have a base
// is a new virtual method and doesn't override anything.
public override bool IsOverride =>
!this._containingType.IsInterface &&
this.IsMetadataVirtual() && !this.IsDestructor &&
((!this.IsMetadataNewSlot() && (object)_containingType.BaseTypeNoUseSiteDiagnostics != null) || this.IsExplicitClassOverride); and a virtual indexer emits:
while an overriding indexer emits:
So everything looks like it should line up here. |
@@ -533,5 +533,99 @@ class Derived: Program | |||
test.ExpectedDiagnostics.Add(VerifyCS.Diagnostic(DetectPreviewFeatureAnalyzer.OverridesPreviewMethodRule).WithLocation(1).WithArguments("AProperty", "Program.AProperty")); | |||
await test.RunAsync(); | |||
} | |||
|
|||
[Fact] | |||
public async Task TestRefProperty() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting that ref T Property
isn't a bug case here; I initially thought it might have been however and there was no coverage for it.
CC. @buyaa-n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Isn't it need to be fixed in 6.0? Then please target release/6.0.1xx
CC @jeffhandley for approval
Does this not have the same general backport policies as dotnet/runtime? |
I assume you would need Tactics approval @tannergooding. main is .NET 7. merging into |
I'll send it for tactics approval tomorrow. I already gave Steve the heads-up it would be coming. |
Retargeted against release/6.0.1xx |
Tactics approved via email |
Customer Impact
The Requires Preview Features Analyzer (CA2252) encounters an unhandled exception in some scenarios when
null
symbols are evaluated. This was discovered while @tannergooding was consuming preview features in the TerraFX project and an indexer property was evaluated.Fix
Defensive code was added to bail from symbol analysis if the symbol is
null
.Testing
Additional test coverage was added for indexer properties. Another test gap of
ref T
properties was identified during this testing, and another test was added for that scenario; the test passed without the fix herein. The fix was also validated against the TerraFX project scenarios.Risks
Very low. Addition of defensive code to prevent an unhandled exception. The code path could never have resulted in a diagnostic being reported for a null symbol, so behavior is otherwise unchanged.