-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Partial properties: merging declarations and emit of simple cases #72999
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
Changes from all commits
f23ba9a
36cbfb0
038e6d3
bc5f89f
1f1a7a0
95cf0a3
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 |
---|---|---|
|
@@ -288,6 +288,8 @@ public override Binder VisitAccessorDeclaration(AccessorDeclarationSyntax parent | |
if ((object)propertySymbol != null) | ||
{ | ||
accessor = (parent.Kind() == SyntaxKind.GetAccessorDeclaration) ? propertySymbol.GetMethod : propertySymbol.SetMethod; | ||
// PROTOTYPE(partial-properties): check if a property with no accessors could fail this assertion, in which case we should either adjust the assertion or remove it. | ||
Debug.Assert(accessor is not null || parent.HasErrors); | ||
} | ||
break; | ||
} | ||
|
@@ -585,18 +587,25 @@ bool checkSymbol(Symbol sym, TextSpan memberSpan, SymbolKind kind, out Symbol re | |
return false; | ||
} | ||
|
||
if (sym.Kind == SymbolKind.Method) | ||
if (kind is SymbolKind.Method or SymbolKind.Property) | ||
{ | ||
if (InSpan(sym.GetFirstLocation(), this.syntaxTree, memberSpan)) | ||
{ | ||
return true; | ||
} | ||
|
||
// If this is a partial method, the method represents the defining part, | ||
// not the implementation (method.Locations includes both parts). If the | ||
// span is in fact in the implementation, return that method instead. | ||
var implementation = ((MethodSymbol)sym).PartialImplementationPart; | ||
if ((object)implementation != null) | ||
// If this is a partial member, the member represents the defining part, | ||
// not the implementation (member.Locations includes both parts). If the | ||
// span is in fact in the implementation, return that member instead. | ||
if (sym switch | ||
#pragma warning disable format | ||
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. nit: could we link to a tracking issue? Is the problem what's described in #46464? 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. Alternatively, take 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. I am not sure, I feel like it is more likely to have the same cause as #73251 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. I would be willing to do either including a link or extracting the switch in a follow-up PR. I almost feel a little defiant toward keeping the current factoring since I want the formatter to be fixed :) 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. I'd like it fixed too :-) But all the related issues are currently marked as Backlog :-/ 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. Done |
||
{ | ||
MethodSymbol method => (Symbol)method.PartialImplementationPart, | ||
jcouv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
SourcePropertySymbol property => property.PartialImplementationPart, | ||
_ => throw ExceptionUtilities.UnexpectedValue(sym) | ||
} | ||
#pragma warning restore format | ||
is { } implementation) | ||
{ | ||
if (InSpan(implementation.GetFirstLocation(), this.syntaxTree, memberSpan)) | ||
RikkiGibson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -474,7 +474,7 @@ internal static bool ShouldEmit(this MethodSymbol method) | |
} | ||
|
||
// Don't emit partial methods without an implementation part. | ||
if (method.IsPartialMethod() && method.PartialImplementationPart is null) | ||
if (method.IsPartialMember() && method.PartialImplementationPart is null) | ||
{ | ||
return false; | ||
} | ||
|
@@ -545,22 +545,28 @@ internal static bool IsExplicitInterfaceImplementation(this Symbol member) | |
} | ||
} | ||
|
||
internal static bool IsPartialMethod(this Symbol member) | ||
internal static bool IsPartialMember(this Symbol member) | ||
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. I did consider introducing some new members on a common base type, or introducing an I am meaning to add a debug assertion that these methods are only used with original definition symbols. I'll try and add a check for that in future PR.
RikkiGibson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
var sms = member as SourceMemberMethodSymbol; | ||
return sms?.IsPartial == true; | ||
return member | ||
is SourceOrdinaryMethodSymbol { IsPartial: true } | ||
or SourcePropertySymbol { IsPartial: true } | ||
or SourcePropertyAccessorSymbol { IsPartial: true }; | ||
} | ||
|
||
internal static bool IsPartialImplementation(this Symbol member) | ||
{ | ||
var sms = member as SourceOrdinaryMethodSymbol; | ||
return sms?.IsPartialImplementation == true; | ||
return member | ||
is SourceOrdinaryMethodSymbol { IsPartialImplementation: true } | ||
or SourcePropertySymbol { IsPartialImplementation: true } | ||
or SourcePropertyAccessorSymbol { IsPartialImplementation: true }; | ||
} | ||
|
||
internal static bool IsPartialDefinition(this Symbol member) | ||
{ | ||
var sms = member as SourceOrdinaryMethodSymbol; | ||
return sms?.IsPartialDefinition == true; | ||
return member | ||
is SourceOrdinaryMethodSymbol { IsPartialDefinition: true } | ||
or SourcePropertySymbol { IsPartialDefinition: true } | ||
or SourcePropertyAccessorSymbol { IsPartialDefinition: true }; | ||
} | ||
|
||
internal static bool ContainsTupleNames(this Symbol member) | ||
|
Uh oh!
There was an error while loading. Please reload this page.