-
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
Extended partial methods #43582
Extended partial methods #43582
Changes from all commits
c95be2c
747393f
3d99838
88ba459
94e8743
a25dfc8
fa9532e
cd76a21
96a7429
3b64567
b262784
3211eb1
ece12e6
16c7335
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1682,10 +1682,13 @@ private void CheckMemberNameConflicts(DiagnosticBag diagnostics) | |
// UNDONE: Consider adding a secondary location pointing to the second method. | ||
private void ReportMethodSignatureCollision(DiagnosticBag diagnostics, SourceMemberMethodSymbol method1, SourceMemberMethodSymbol method2) | ||
{ | ||
// Partial methods are allowed to collide by signature. | ||
if (method1.IsPartial && method2.IsPartial) | ||
switch (method1, method2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Does this Unless there is a change in behavior, we should stick with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this fixes #43883. This solution ends up creating additional diagnostics in some error scenarios. I tried moving the checks for PartialMethodOnlyOneLatent/PartialMethodOnlyOneActual in here, but because partial method merging already happened in an earlier step, it causes us to miss diagnostics for multiple "actual" methods. If we could do this at the same time or right before we merge partial methods, we might be able to get higher quality diagnostics in some scenarios when members have conflicting signatures:
It might also be possible to fix this by modifying the partial method signature comparer, that groups declarations that might be part of the same partial method, to be aware of RefKind differences. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That sounds ok. We can revisit this later if necessary. In reply to: 418977822 [](ancestors = 418977822) |
||
{ | ||
return; | ||
case (SourceOrdinaryMethodSymbol { IsPartialDefinition: true }, SourceOrdinaryMethodSymbol { IsPartialImplementation: true }): | ||
case (SourceOrdinaryMethodSymbol { IsPartialImplementation: true }, SourceOrdinaryMethodSymbol { IsPartialDefinition: true }): | ||
// these could be 2 parts of the same partial method. | ||
// Partial methods are allowed to collide by signature. | ||
return; | ||
} | ||
|
||
// If method1 is a constructor only because its return type is missing, then | ||
|
@@ -2566,6 +2569,10 @@ private static void MergePartialMembers( | |
{ | ||
diagnostics.Add(ErrorCode.ERR_PartialMethodInconsistentTupleNames, method.Locations[0], method, method.OtherPartOfPartial); | ||
} | ||
else if (method is { IsPartialDefinition: true, OtherPartOfPartial: null, HasExplicitAccessModifier: true }) | ||
{ | ||
diagnostics.Add(ErrorCode.ERR_PartialMethodWithAccessibilityModsMustHaveImplementation, method.Locations[0], method); | ||
} | ||
} | ||
} | ||
} | ||
|
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.
Based on the LDM discussions we should not have separate errors for these violations. The requirement for an implementation is dictated by the presence of an explicit accessibility modifier. That is what mandates their is an implementation, not everything else.
At the same time all of these new scenarios must be predicated on an explicit accessibility modifier. Basically if you see
out
that is illegal unless there is an explicit accessibility modifierThere 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.
Fixed