Skip to content

Use record keyword to display records#46338

Merged
jcouv merged 9 commits intodotnet:masterfrom
jcouv:record-info
Jul 29, 2020
Merged

Use record keyword to display records#46338
jcouv merged 9 commits intodotnet:masterfrom
jcouv:record-info

Conversation

@jcouv
Copy link
Member

@jcouv jcouv commented Jul 26, 2020

Fixes #45015

@jcouv jcouv self-assigned this Jul 26, 2020
@jcouv jcouv added this to the 16.8 milestone Jul 26, 2020
@jcouv jcouv marked this pull request as ready for review July 27, 2020 01:20
@jcouv jcouv requested review from a team as code owners July 27, 2020 01:20
{
switch (symbol.TypeKind)
{
case TypeKind.Class when !symbol.GetMembers(WellKnownMemberNames.CloneMethodName).IsEmpty:
Copy link
Contributor

@AlekseyTs AlekseyTs Jul 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Contributor

@AlekseyTs AlekseyTs Jul 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Jul 27, 2020

Done with review pass (iteration 1) #Closed

@jcouv jcouv requested a review from AlekseyTs July 28, 2020 14:19
static bool hasCloneMethod(INamedTypeSymbol symbol)
{
HashSet<DiagnosticInfo> ignored = null;
return symbol is Symbols.PublicModel.NamedTypeSymbol namedTypeSymbol &&
Copy link
Contributor

@AlekseyTs AlekseyTs Jul 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Jul 28, 2020

Done with review pass (iteration 2) #Closed

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Jul 28, 2020

    public void Clone_05()

Could you please preserve the number in the name at the same position? #Closed


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs:1575 in 4fdfe55. [](commit_id = 4fdfe55, deletion_comment = True)

@jcouv jcouv requested a review from AlekseyTs July 28, 2020 23:48

return candidate;

bool IsEqualToOrDerivedFrom(ITypeSymbol one, ITypeSymbol other, SymbolEqualityComparer comparison)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this local function be static?


In reply to: 461958297 [](ancestors = 461958297)


return candidate;

bool IsEqualToOrDerivedFrom(ITypeSymbol one, ITypeSymbol other, SymbolEqualityComparer comparison)
Copy link
Contributor

@AlekseyTs AlekseyTs Jul 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsEqualToOrDerivedFrom [](start = 17, length = 22)

Is this a local function? The name shouldn't start with a capital letter. #Closed

}

[Fact]
public void RecordLoadedInVisualBasicDisplaysAsRecord()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RecordLoadedInVisualBasicDisplaysAsRecord [](start = 20, length = 41)

Consider moving to SymbolDisplayTests.

@dotnet dotnet deleted a comment from jcouv Jul 28, 2020

return candidate;

bool IsEqualToOrDerivedFrom(ITypeSymbol one, ITypeSymbol other, SymbolEqualityComparer comparison)
Copy link
Contributor

@AlekseyTs AlekseyTs Jul 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SymbolEqualityComparer comparison [](start = 76, length = 33)

We are always passing a singleton, is there a reason to pass it as an argument? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trying to keep code closer to original

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Jul 29, 2020

Done with review pass (iteration 5) #Closed

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (iteration 7)

/// <summary>
/// Copy of <see cref="SynthesizedRecordClone.FindValidCloneMethod(TypeSymbol, ref HashSet{DiagnosticInfo}?)"/>
/// </summary>
internal static IMethodSymbol FindValidCloneMethod(ITypeSymbol containingType)
Copy link
Contributor

@cston cston Jul 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal [](start = 8, length = 8)

private #Closed

{
if (candidate is object)
{
// An ammbiguity case, can come from metadata, treat as an error for simplicity.
Copy link
Contributor

@cston cston Jul 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ammbiguity [](start = 30, length = 10)

Typo. #Closed

}

return false;
}
Copy link
Contributor

@cston cston Jul 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} [](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

@jcouv jcouv merged commit 64bbbc4 into dotnet:master Jul 29, 2020
@ghost ghost modified the milestones: 16.8, Next Jul 29, 2020
@jcouv jcouv deleted the record-info branch July 29, 2020 22:02
333fred added a commit to 333fred/roslyn that referenced this pull request Jul 31, 2020
* 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
  ...
@RikkiGibson RikkiGibson modified the milestones: Next, 16.8.P2 Aug 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

QuickInfo: display records as record instead of class

7 participants