Skip to content

Covariant returns part 3#43797

Merged
gafter merged 7 commits intodotnet:features/covariant-returnsfrom
gafter:covariant-returns-part3
May 8, 2020
Merged

Covariant returns part 3#43797
gafter merged 7 commits intodotnet:features/covariant-returnsfrom
gafter:covariant-returns-part3

Conversation

@gafter
Copy link
Member

@gafter gafter commented Apr 29, 2020

  • Test that covariant returns are recognized by the compiler from compilation references.
  • Test that covariant methods imply metadata newslot and a methodimpl table entry.
  • Test the type returned from calling a covariantly overridden method.
  • Test that the compiler APIs agree whether viewed from source or metadata.
  • Test VB consumption and overriding of covariant return methods declared in C#.
  • Read covariant return override information [methodimpl] from metadata.

@gafter gafter added Area-Compilers Feature - Covariant Returns Permit an override to return a more specific reference type labels Apr 29, 2020
@gafter gafter added this to the Compiler.Net5 milestone Apr 29, 2020
@gafter gafter self-assigned this Apr 29, 2020
@gafter gafter mentioned this pull request May 4, 2020
@gafter gafter force-pushed the covariant-returns-part3 branch from 0932ad2 to 2052dca Compare May 4, 2020 22:07
@gafter gafter requested review from a team, AlekseyTs and RikkiGibson May 5, 2020 19:58
@gafter gafter marked this pull request as ready for review May 5, 2020 19:58
@gafter
Copy link
Member Author

gafter commented May 5, 2020

@dotnet/roslyn-compiler May I please have a review of these changes for covariant returns? This set of changes focuses on getting things working the same in source, compilation references, and metadata. #Resolved

@gafter gafter mentioned this pull request May 6, 2020
@AlekseyTs
Copy link
Contributor

AlekseyTs commented May 7, 2020

It doesn't look like metadata encoding is specified in https://github.com/dotnet/csharplang/blob/master/proposals/covariant-returns.md. Is there a different specification for that? #Closed

@gafter
Copy link
Member Author

gafter commented May 7, 2020

@AlekseyTs https://github.com/dotnet/csharplang/blob/master/proposals/covariant-returns.md is a specification of the C# language change. The metadata specification is maintained by the runtime team, and you have been CC'ed on the relevant threads. A runtime design document is under review in dotnet/runtime#35308 and I expect that PR will be extended to include a draft augment for ECMA-335.

I think I've responded to all of your comments. Do you have any others? #Resolved

@AlekseyTs
Copy link
Contributor

AlekseyTs commented May 7, 2020

Done reviewing compiler changes (iteration 7), tests are not looked at. #Closed

@gafter
Copy link
Member Author

gafter commented May 7, 2020

@AlekseyTs I believe I've responded to all of your comments. Do you have any others? #Resolved

@gafter
Copy link
Member Author

gafter commented May 8, 2020

@AlekseyTs I believe I've responded to all of your comments. Do you have any others? #Resolved

{
VerifyOverride(comp, "Derived.this[]", "System.String Derived.this[System.Int32 i] { get; }", "System.Object Base.this[System.Int32 i] { get; }");
VerifyOverride(comp, "Derived.get_Item", "System.String Derived.this[System.Int32 i].get", "System.Object Base.this[System.Int32 i].get");
VerifyAssignments(comp);
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

VerifyAssignments [](start = 16, length = 17)

Same question. #Resolved

{
VerifyOverride(comp, "Derived.this[]", "U Derived<T, U>.this[System.Int32 i] { get; }", "T Base<T>.this[System.Int32 i] { get; }");
VerifyOverride(comp, "Derived.get_Item", "U Derived<T, U>.this[System.Int32 i].get", "T Base<T>.this[System.Int32 i].get");
VerifyAssignments(comp);
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

VerifyAssignments [](start = 16, length = 17)

Same question. #Resolved

{
VerifyOverride(comp, "Derived.this[]", "T Derived<T>.this[System.Int32 i] { get; }", "N Base.this[System.Int32 i] { get; }");
VerifyOverride(comp, "Derived.get_Item", "T Derived<T>.this[System.Int32 i].get", "N Base.this[System.Int32 i].get");
VerifyAssignments(comp);
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

Same question. #Resolved

VerifyOverride(comp, "Derived.P", "System.Func<System.String> Derived.P { get; set; }", "System.Func<System.Object> Base.P { get; set; }");
VerifyNoOverride(comp, "Derived.set_P");
VerifyOverride(comp, "Derived.get_P", "System.Func<System.String> Derived.P.get", "System.Func<System.Object> Base.P.get");
VerifyAssignments(comp);
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

VerifyAssignments [](start = 16, length = 17)

Same question. #Resolved

static void verify(CSharpCompilation comp)
{
VerifyOverride(comp, "Derived.M", "System.String Derived.M()", "System.Object Base.M()");
VerifyAssignments(comp);
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

VerifyAssignments [](start = 16, length = 17)

Same question. #Resolved

{
VerifyOverride(comp, "Derived.M", "System.String Derived.M { get; }", "System.Object Base.M { get; }");
VerifyOverride(comp, "Derived.get_M", "System.String Derived.M.get", "System.Object Base.M.get");
VerifyAssignments(comp);
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

Same question. #Resolved

{
VerifyOverride(comp, "Derived.this[]", "System.String Derived.this[System.Int32 i] { get; }", "System.Object Base.this[System.Int32 i] { get; }");
VerifyOverride(comp, "Derived.get_Item", "System.String Derived.this[System.Int32 i].get", "System.Object Base.this[System.Int32 i].get");
VerifyAssignments(comp);
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

VerifyAssignments [](start = 16, length = 17)

Same question. #Resolved

static void verify(CSharpCompilation comp)
{
VerifyOverride(comp, "Derived.M", "System.String Derived.M()", "System.Object Base.M()");
VerifyAssignments(comp);
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

VerifyAssignments [](start = 16, length = 17)

Same question. #Resolved

static void verify(CSharpCompilation comp)
{
VerifyOverride(comp, "Derived.M", "System.Object Derived.M()", "System.String Base.M()");
VerifyAssignments(comp);
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

VerifyAssignments [](start = 16, length = 17)

Same question. #Resolved

VerifyNoOverride(comp, "Derived2.M2");
VerifyNoOverride(comp, "Derived3.M1");
VerifyNoOverride(comp, "Derived3.M2");
VerifyAssignments(comp);
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

VerifyAssignments [](start = 16, length = 17)

Same question. #Resolved

VerifyOverride(comp, "Derived2.M3", "Base Derived2.M3 { get; }", "System.String Derived.M3 { get; }");
VerifyOverride(comp, "Derived2.get_M3", "Base Derived2.M3.get", "System.String Derived.M3.get");

VerifyAssignments(comp);
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

VerifyAssignments [](start = 16, length = 17)

Same question. #Resolved

VerifyOverride(comp, "Derived.get_M1", "IIn<System.Object> Derived.M1.get", "IIn<System.String> Base.M1.get");
VerifyOverride(comp, "Derived.M2", "IOut<System.String> Derived.M2 { get; }", "IOut<System.Object> Base.M2 { get; }");
VerifyOverride(comp, "Derived.get_M2", "IOut<System.String> Derived.M2.get", "IOut<System.Object> Base.M2.get");
VerifyAssignments(comp);
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

VerifyAssignments [](start = 16, length = 17)

Same question. #Resolved

VerifyOverride(comp, "Derived.get_M1", "IIn<System.String> Derived.M1.get", "IIn<System.Object> Base.M1.get");
VerifyOverride(comp, "Derived.M2", "IOut<System.Object> Derived.M2 { get; }", "IOut<System.String> Base.M2 { get; }");
VerifyOverride(comp, "Derived.get_M2", "IOut<System.Object> Derived.M2.get", "IOut<System.String> Base.M2.get");
VerifyAssignments(comp);
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

VerifyAssignments [](start = 16, length = 17)

Same question. #Resolved

VerifyOverride(comp, "Derived.get_M1", "System.Int16 Derived.M1.get", "System.Int32 Base.M1.get");
VerifyOverride(comp, "Derived.M2", "B Derived.M2 { get; }", "A Base.M2 { get; }");
VerifyOverride(comp, "Derived.get_M2", "B Derived.M2.get", "A Base.M2.get");
VerifyAssignments(comp);
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

VerifyAssignments [](start = 16, length = 17)

Same question. #Resolved

{
VerifyOverride(comp, "Derived.M", "System.String Derived.M { get; }", "System.IComparable Base.M { get; }");
VerifyOverride(comp, "Derived.get_M", "System.String Derived.M.get", "System.IComparable Base.M.get");
VerifyAssignments(comp);
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

VerifyAssignments [](start = 16, length = 17)

Same question. #Resolved

VerifyNoOverride(comp, "Derived.Base.M2");
VerifyNoOverride(comp, "C.Base.M1");
VerifyNoOverride(comp, "C.Base.M2");
VerifyAssignments(comp);
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

VerifyAssignments [](start = 16, length = 17)

Same question. #Resolved

{
VerifyOverride(comp, "Derived.P", "System.String Derived.P { get; }", "System.Object Base.P { get; set; }");
VerifyOverride(comp, "Derived.get_P", "System.String Derived.P.get", "System.Object Base.P.get");
VerifyAssignments(comp);
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

VerifyAssignments [](start = 16, length = 17)

Same question. #Resolved

VerifyOverride(comp, "Derived2.P", "System.String Derived2.P { get; set; }", "System.String Derived.P { get; }");
VerifyOverride(comp, "Derived2.get_P", "System.String Derived2.P.get", "System.String Derived.P.get");
VerifyNoOverride(comp, "Derived2.set_P");
VerifyAssignments(comp);
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

VerifyAssignments [](start = 16, length = 17)

Same question. #Resolved

VerifyOverride(comp, "Derived.get_P", "System.String Derived.P.get", "System.Object Base.P.get");
VerifyOverride(comp, "Derived2.P", "System.String Derived2.P { set; }", "System.String Derived.P { get; }");
VerifyNoOverride(comp, "Derived2.set_P");
VerifyAssignments(comp);
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

VerifyAssignments [](start = 16, length = 17)

Same question. #Resolved

VerifyOverride(comp, "Derived.get_P", "System.IComparable Derived.P.get", "System.Object Base.P.get");
VerifyOverride(comp, "Derived2.P", "System.String Derived2.P { get; }", "System.IComparable Derived.P { get; }");
VerifyOverride(comp, "Derived2.get_P", "System.String Derived2.P.get", "System.IComparable Derived.P.get");
VerifyAssignments(comp);
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

VerifyAssignments [](start = 16, length = 17)

Same question. #Resolved

static void verify(CSharpCompilation comp)
{
VerifyOverride(comp, "Derived.M", "System.String Derived.M(System.String s)", "System.Object Base<System.String>.M(System.String s)");
VerifyAssignments(comp);
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

VerifyAssignments [](start = 16, length = 17)

Same question. #Resolved

{
VerifyOverride(comp, "Derived.M", "System.IComparable Derived.M()", "System.Object Base.M()");
VerifyOverride(comp, "Derived2.M", "System.String Derived2.M()", "System.IComparable Derived.M()");
VerifyAssignments(comp);
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

VerifyAssignments [](start = 16, length = 17)

Same question. #Resolved

count++;
var initialValue = declarator.Initializer.Value;
var typeInfo = model.GetTypeInfo(initialValue);
Assert.True(typeInfo.Type.Equals(typeInfo.ConvertedType, TypeCompareKind.AllIgnoreOptions));
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

Equals [](start = 46, length = 6)

What API is called here? #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.

This is calling Test.Utilities.Equals(this ITypeSymbol first, ITypeSymbol second, Microsoft.CodeAnalysis.TypeCompareKind typeCompareKind)
However, the ignore options aren't needed so this is changed to Assert.Equal(typeInfo.Type, typeInfo.ConvertedType) in the following PR.


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

@AlekseyTs
Copy link
Contributor

AlekseyTs commented May 8, 2020

Done with review pass (iteration 7) #Closed

{
if (IsExplicitClassOverride)
{
foreach (MethodSymbol method in ExplicitlyOverriddenMethods())
Copy link
Contributor

@AlekseyTs AlekseyTs May 8, 2020

Choose a reason for hiding this comment

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

ExplicitlyOverriddenMethods [](start = 52, length = 27)

I think it would be good to test scenarios when we fail to successfully resolve a MethodImpl. For example, the method is not found in the type, or the type is not found. Cover scenarios when the type is a class and an interface. Also in presence of other resolvable MethodImpls, from classes and interfaces, all combinations. #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

This suggestion is tracked at #44079


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

@gafter
Copy link
Member Author

gafter commented May 8, 2020

@AlekseyTs I believe I've responded to all of your comments. Do you have any others?

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.

Signing-off on iteration 7 with assumption that feedback is going to be addressed in the next PR, unless tracked by an issue.

@gafter
Copy link
Member Author

gafter commented May 8, 2020

You can see the issues already filed as noted and feedback already addressed in #44025

@gafter gafter merged commit 2167092 into dotnet:features/covariant-returns May 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers Feature - Covariant Returns Permit an override to return a more specific reference type

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants