Use record keyword to display records#46338
Conversation
| { | ||
| switch (symbol.TypeKind) | ||
| { | ||
| case TypeKind.Class when !symbol.GetMembers(WellKnownMemberNames.CloneMethodName).IsEmpty: |
There was a problem hiding this comment.
!symbol.GetMembers(WellKnownMemberNames.CloneMethodName).IsEmpty [](start = 49, length = 64)
I think we should duplicate the filter condition from SynthesizedRecordClone.FindValidCloneMethod and leave a comment there to keep this place in sync in case of future changes to the logic. #Closed
There was a problem hiding this comment.
I'm okay to do the more complete check, but would prefer not to duplicate logic. I'm pushing a change to leverage FindValidCloneMethod. Let me know if okay
| } | ||
|
|
||
| [Fact] | ||
| public void RecordDeclaration() |
There was a problem hiding this comment.
RecordDeclaration [](start = 20, length = 17)
In RecordTests.cs we have a bunch of IL tests with invalid Clone declarations, I think we should add a ToTestDisplayString validation to them. #Closed
|
Done with review pass (iteration 1) #Closed |
| static bool hasCloneMethod(INamedTypeSymbol symbol) | ||
| { | ||
| HashSet<DiagnosticInfo> ignored = null; | ||
| return symbol is Symbols.PublicModel.NamedTypeSymbol namedTypeSymbol && |
There was a problem hiding this comment.
symbol is Symbols.PublicModel.NamedTypeSymbol namedTypeSymbol [](start = 23, length = 61)
This looks wrong. Please add a test that imports a record to VB, gets a symbol for it (VB symbol) and pushes it through here by feeding the symbol to C# symbol display. This is a supported scenario. #Closed
|
Done with review pass (iteration 2) #Closed |
|
|
||
| return candidate; | ||
|
|
||
| bool IsEqualToOrDerivedFrom(ITypeSymbol one, ITypeSymbol other, SymbolEqualityComparer comparison) |
There was a problem hiding this comment.
|
|
||
| return candidate; | ||
|
|
||
| bool IsEqualToOrDerivedFrom(ITypeSymbol one, ITypeSymbol other, SymbolEqualityComparer comparison) |
There was a problem hiding this comment.
IsEqualToOrDerivedFrom [](start = 17, length = 22)
Is this a local function? The name shouldn't start with a capital letter. #Closed
| } | ||
|
|
||
| [Fact] | ||
| public void RecordLoadedInVisualBasicDisplaysAsRecord() |
There was a problem hiding this comment.
RecordLoadedInVisualBasicDisplaysAsRecord [](start = 20, length = 41)
Consider moving to SymbolDisplayTests.
|
|
||
| return candidate; | ||
|
|
||
| bool IsEqualToOrDerivedFrom(ITypeSymbol one, ITypeSymbol other, SymbolEqualityComparer comparison) |
There was a problem hiding this comment.
SymbolEqualityComparer comparison [](start = 76, length = 33)
We are always passing a singleton, is there a reason to pass it as an argument? #Closed
There was a problem hiding this comment.
trying to keep code closer to original
There was a problem hiding this comment.
trying to keep code closer to original
I do not believe this is useful, this method already diverged significantly from the one we are trying to clone
In reply to: 461962590 [](ancestors = 461962590)
|
Done with review pass (iteration 5) #Closed |
| /// <summary> | ||
| /// Copy of <see cref="SynthesizedRecordClone.FindValidCloneMethod(TypeSymbol, ref HashSet{DiagnosticInfo}?)"/> | ||
| /// </summary> | ||
| internal static IMethodSymbol FindValidCloneMethod(ITypeSymbol containingType) |
There was a problem hiding this comment.
internal [](start = 8, length = 8)
private #Closed
| { | ||
| if (candidate is object) | ||
| { | ||
| // An ammbiguity case, can come from metadata, treat as an error for simplicity. |
There was a problem hiding this comment.
ammbiguity [](start = 30, length = 10)
Typo. #Closed
| } | ||
|
|
||
| return false; | ||
| } |
There was a problem hiding this comment.
} [](start = 12, length = 1)
Consider using a single call to Equals() and a single call to BaseType.
do
{
if (one.Equals(other, comparison)) return true;
one = one.BaseType;
} while (one != null);
return false;
``` #Closed* upstream/master: (304 commits) Tweak diagnostics to account for records (dotnet#46341) Diagnose precedence inversion in a warning wave (dotnet#46239) Remove PROTOTYPE tag (dotnet#45965) Only run a single pass of NullableWalker per-member (dotnet#46402) Fix crash, and offer "declare as nullable" for tuple fields (dotnet#46437) Simplify contract for RunWithShutdownBlockAsync Fix optprof plugin input check if EditorAdaptersFactoryService gives us a null buffer Cannot assign maybe-null value to TNotNull variable (dotnet#41445) Fix overload resolution to handle binary compat in the face of covariant returns (dotnet#46367) Same failure on Linux Skip some tests on Mac Added search option for inline parameter name hints Spelling tweak docs Improve comment Improve the "not exhaustive" diagnostic in the presence of a when clause. (dotnet#46143) PR feedback Use record keyword to display records (dotnet#46338) remove test that aserts .NET Standard should be prefered over .NET Framework ...
Fixes #45015