-
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
Fix Function Pointer RefKind Display #51223
Changes from 7 commits
9c99cbc
a3f324d
ad7ddea
04b0378
ef0d6cc
d31a3dc
cfbe45c
9799b7d
6f6e883
e3f11f5
18f2bde
cb03900
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 |
---|---|---|
|
@@ -609,7 +609,17 @@ void visitFunctionPointerSignature(IMethodSymbol symbol) | |
|
||
foreach (var param in symbol.Parameters) | ||
{ | ||
param.Accept(this.NotFirstVisitor); | ||
if (format.MemberOptions.IncludesOption(SymbolDisplayMemberOptions.IncludeRef)) | ||
{ | ||
AddParameterRefKind(param.RefKind); | ||
} | ||
|
||
AddCustomModifiersIfRequired(param.RefCustomModifiers); | ||
|
||
param.Type.Accept(this.NotFirstVisitor); | ||
|
||
AddCustomModifiersIfRequired(param.CustomModifiers, leadingSpace: true, trailingSpace: false); | ||
|
||
AddPunctuation(SyntaxKind.CommaToken); | ||
AddSpace(); | ||
} | ||
|
@@ -679,9 +689,13 @@ public override void VisitParameter(IParameterSymbol symbol) | |
// used on their own or in the context of methods. | ||
|
||
var includeType = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeType); | ||
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.
It appears an extra empty line was added above this line. Could be an issue with the diff tool though. #Closed |
||
var includeName = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeName) | ||
&& !(symbol.ContainingSymbol is IMethodSymbol { MethodKind: MethodKind.FunctionPointerSignature }); | ||
var includeName = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeName) && | ||
symbol.Name.Length != 0; | ||
var includeBrackets = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeOptionalBrackets); | ||
var includeOption = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeDefaultValue) && | ||
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.
The name "includeOption" feels somewhat confusing. "includeDefaultValue" ? #Closed |
||
format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeName) && | ||
symbol.HasExplicitDefaultValue && | ||
CanAddConstant(symbol.Type, symbol.ExplicitDefaultValue); | ||
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. With the latest changes to how function pointers are printed, are any of these changes to |
||
|
||
if (includeBrackets && symbol.IsOptional) | ||
{ | ||
|
@@ -703,26 +717,26 @@ public override void VisitParameter(IParameterSymbol symbol) | |
AddCustomModifiersIfRequired(symbol.CustomModifiers, leadingSpace: true, trailingSpace: false); | ||
} | ||
|
||
if (includeName && includeType) | ||
{ | ||
AddSpace(); | ||
} | ||
|
||
if (includeName) | ||
{ | ||
if (includeType) | ||
{ | ||
AddSpace(); | ||
} | ||
var kind = symbol.IsThis ? SymbolDisplayPartKind.Keyword : SymbolDisplayPartKind.ParameterName; | ||
builder.Add(CreatePart(kind, symbol, symbol.Name)); | ||
} | ||
|
||
if (format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeDefaultValue) && | ||
symbol.HasExplicitDefaultValue && | ||
CanAddConstant(symbol.Type, symbol.ExplicitDefaultValue)) | ||
if (includeOption) | ||
{ | ||
if (includeName || includeType) | ||
{ | ||
AddSpace(); | ||
AddPunctuation(SyntaxKind.EqualsToken); | ||
AddSpace(); | ||
|
||
AddConstantValue(symbol.Type, symbol.ExplicitDefaultValue); | ||
} | ||
AddPunctuation(SyntaxKind.EqualsToken); | ||
AddSpace(); | ||
|
||
AddConstantValue(symbol.Type, symbol.ExplicitDefaultValue); | ||
} | ||
|
||
if (includeBrackets && symbol.IsOptional) | ||
|
@@ -967,21 +981,26 @@ private void AddParameterRefKindIfRequired(RefKind refKind) | |
{ | ||
if (format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeParamsRefOut)) | ||
{ | ||
switch (refKind) | ||
{ | ||
case RefKind.Out: | ||
AddKeyword(SyntaxKind.OutKeyword); | ||
AddSpace(); | ||
break; | ||
case RefKind.Ref: | ||
AddKeyword(SyntaxKind.RefKeyword); | ||
AddSpace(); | ||
break; | ||
case RefKind.In: | ||
AddKeyword(SyntaxKind.InKeyword); | ||
AddSpace(); | ||
break; | ||
} | ||
AddParameterRefKind(refKind); | ||
} | ||
} | ||
|
||
private void AddParameterRefKind(RefKind refKind) | ||
{ | ||
switch (refKind) | ||
{ | ||
case RefKind.Out: | ||
AddKeyword(SyntaxKind.OutKeyword); | ||
AddSpace(); | ||
break; | ||
case RefKind.Ref: | ||
AddKeyword(SyntaxKind.RefKeyword); | ||
AddSpace(); | ||
break; | ||
case RefKind.In: | ||
AddKeyword(SyntaxKind.InKeyword); | ||
AddSpace(); | ||
break; | ||
} | ||
} | ||
} | ||
|
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.
It looks like this breaks some tests because diagnostics now doesn't display ref-ness of parameter types by default. Perhaps we should display ref-ness in function pointer types unconditionally (including return ref-ness)? #Closed
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.
I'm ok with that
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.
@333fred
What do you think? Another option is to add a whole new display option (SymbolDisplayMiscellaneousOptions?) that controls that for function pointer types.
In reply to: 592331577 [](ancestors = 592331577)
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.
It looks like all the remaining broken tests are due to this issue. I'm going to wait to fix them till a decision is made.
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.
I think we should do this. You can overload methods by function-pointer-parameter-refness, so if you had
M(delegate*<ref string, void>)
andM(delegate*<string, void>)
, that would lead to bad diagnostics.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.
It looks like we are converging on displaying ref-ness in function pointer types unconditionally (including the return ref-ness)
In reply to: 592505606 [](ancestors = 592505606)