Skip to content

Enable declaration, implementation(in non-interfaces) and consumption of virtual static members.#60965

Merged
AlekseyTs merged 9 commits intodotnet:features/DefaultInterfaceImplementationfrom
AlekseyTs:DefaultInterfaceImplementation_102
May 4, 2022
Merged

Enable declaration, implementation(in non-interfaces) and consumption of virtual static members.#60965
AlekseyTs merged 9 commits intodotnet:features/DefaultInterfaceImplementationfrom
AlekseyTs:DefaultInterfaceImplementation_102

Conversation

@AlekseyTs
Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs commented Apr 26, 2022

Copy link
Copy Markdown
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

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

Reviewed everything except StaticAbstractMembersInInterfacesTests.cs. Will get to that tomorrow.

@AlekseyTs AlekseyTs requested review from a team and JoeRobich as code owners April 29, 2022 14:10
@AlekseyTs AlekseyTs requested a review from a team April 29, 2022 14:10
…ntation' into DefaultInterfaceImplementation_102
@@ -73,9 +73,9 @@ sealed override static void M10()
// (4,26): error CS8703: The modifier 'abstract' is not valid for this item in C# 9.0. Please use language version 'preview' or greater.
// abstract static void M01()
Diagnostic(ErrorCode.ERR_InvalidModifierForLanguageVersion, "M01").WithArguments("abstract", "9.0", "preview").WithLocation(4, 26),
// (7,25): error CS0112: A static member cannot be marked as 'virtual'
// (7,25): error CS8703: The modifier 'virtual' is not valid for this item in C# 9.0. Please use language version 'preview' or greater.
Copy link
Copy Markdown
Member

@333fred 333fred Apr 29, 2022

Choose a reason for hiding this comment

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

Should we update this and other tests that use C# 9 to 10? #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should we update this and other tests that use C# 9 to 10?

Yes, I am planning to do this in a separate PR to reduce the noise.

Copy link
Copy Markdown
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

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

LGTM (commit 9). Future reviews, I recommend turning off whitespace to avoid a decent chunk of changes in some of the test files.

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

AlekseyTs commented Apr 29, 2022

@jcouv, @dotnet/roslyn-compiler For the second review.


In reply to: 1113626786

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

AlekseyTs commented May 2, 2022

@dotnet/roslyn-compiler For the second review.


In reply to: 1114895031

MessageID.IDS_FeatureStaticAbstractMembersInInterfaces.Localize(),
availableVersion.GetValueOrDefault().ToDisplayString(),
new CSharpRequiredLanguageVersion(requiredVersion));
}
Copy link
Copy Markdown
Contributor

@cston cston May 2, 2022

Choose a reason for hiding this comment

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

Please consider extracting this to a local function that can be reused for IDS_DefaultInterfaceImplementation above. #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Please consider extracting this to a local function that can be reused for IDS_DefaultInterfaceImplementation above.

I will follow up on this suggestion separately.

@@ -512,7 +512,8 @@ private BoundExpression MakeConversionNodeCore(
var mg = (BoundMethodGroup)rewrittenOperand;
Debug.Assert(oldNodeOpt.SymbolOpt is { });
Copy link
Copy Markdown
Contributor

@cston cston May 3, 2022

Choose a reason for hiding this comment

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

oldNodeOpt.SymbolOpt

Consider extracting a local. #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Consider extracting a local.

I will follow up on this suggestion separately.

var availableVersionArgument = availableVersion.ToDisplayString();

reportModifierIfPresent(result, DeclarationModifiers.Abstract, location, diagnostics, requiredVersionArgument, availableVersionArgument);
if ((result & DeclarationModifiers.Abstract) != 0)
Copy link
Copy Markdown
Contributor

@cston cston May 3, 2022

Choose a reason for hiding this comment

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

if ((result & DeclarationModifiers.Abstract) != 0)

Why check this rather than calling reportModifierIfPresent() unconditionally, for DeclarationModifiers.Abstract and DeclarationModifiers.Sealed? #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why check this rather than calling

Suppresses extra diagnostics for "abstract virtual" case

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think there is a dedicated error reported for this case elsewhere.

@cston
Copy link
Copy Markdown
Contributor

cston commented May 4, 2022

                foreach (var reference in new[] { compilation1.ToMetadataReference(), compilation1.EmitToImageReference() })

Why is Test1 included in the compilation with Test2? Does that affect the test? (Is Test2 a copy of Test1 that is used for compiling in a separate compilation from the interface declaration?)


In reply to: 1116901341


Refers to: src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs:174 in a28883d. [](commit_id = a28883d, deletion_comment = False)

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

                foreach (var reference in new[] { compilation1.ToMetadataReference(), compilation1.EmitToImageReference() })

Why is Test1 included in the compilation with Test2?

source2 includes only Test2, it doesn't include Test1. Test1 is defined in a referenced assembly.

Does that affect the test?
Presence of Test1 in the referenced assembly doesn't affect any validation around compilation2. As presence of hundreds of other types in other referenced assemblies.

Is Test2 a copy of Test1 that is used for compiling in a separate compilation from the interface declaration?

Yes, I think the only difference is the name of the type.


In reply to: 1116901341


Refers to: src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs:174 in a28883d. [](commit_id = a28883d, deletion_comment = False)

@cston
Copy link
Copy Markdown
Contributor

cston commented May 4, 2022

            // (50,22): error CS0539: 'C8.op_UnaryPlus(C8)' in explicit interface declaration is not found among members of the interface that can be implemented

Why is the C8 implementation invalid?


In reply to: 1117727936


In reply to: 1117727936


Refers to: src/Compilers/CSharp/Test/Symbol/Symbols/StaticAbstractMembersInInterfacesTests.cs:16896 in a28883d. [](commit_id = a28883d, deletion_comment = False)

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

            // (50,22): error CS0539: 'C8.op_UnaryPlus(C8)' in explicit interface declaration is not found among members of the interface that can be implemented

Why is the C8 implementation invalid?

It is not using operator syntax, it is trying to refer to the operator as to a regular method by name.


In reply to: 1117727936


Refers to: src/Compilers/CSharp/Test/Symbol/Symbols/StaticAbstractMembersInInterfacesTests.cs:16896 in a28883d. [](commit_id = a28883d, deletion_comment = False)

@cston
Copy link
Copy Markdown
Contributor

cston commented May 4, 2022

            // (27,19): error CS0106: The modifier 'static' is not valid for this item

Why is static not valid for the implementation?


In reply to: 1117832578


Refers to: src/Compilers/CSharp/Test/Symbol/Symbols/StaticAbstractMembersInInterfacesTests.cs:21698 in a28883d. [](commit_id = a28883d, deletion_comment = False)

@cston
Copy link
Copy Markdown
Contributor

cston commented May 4, 2022

            // (11,37): warning CS0473: Explicit interface implementation 'Other.Interface<int, int>.Method(int)' matches more than one interface member. Which interface member is actually chosen is implementation-dependent. Consider using a non-explicit implementation instead.

Why a warning for new scenarios?


In reply to: 1117853635


Refers to: src/Compilers/CSharp/Test/Symbol/Symbols/StaticAbstractMembersInInterfacesTests.cs:30459 in a28883d. [](commit_id = a28883d, deletion_comment = False)

BC30275: 'Overridable' is not valid on an interface event declaration.
Overridable Shared Event E1 As System.Action
~~~~~~~~~~~
</errors>
Copy link
Copy Markdown
Contributor

@cston cston May 4, 2022

Choose a reason for hiding this comment

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

errors

Please also test with Shared only, not Overridable. #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Please also test with Shared only, not Overridable.

Isn't this the previous test?

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

AlekseyTs commented May 4, 2022

            // (27,19): error CS0106: The modifier 'static' is not valid for this item

Why is static not valid for the implementation?

Because implementations inside interfaces are out of scope of this PR. The next PR is focused on this.


In reply to: 1117832578


Refers to: src/Compilers/CSharp/Test/Symbol/Symbols/StaticAbstractMembersInInterfacesTests.cs:21698 in a28883d. [](commit_id = a28883d, deletion_comment = False)

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

            // (11,37): warning CS0473: Explicit interface implementation 'Other.Interface<int, int>.Method(int)' matches more than one interface member. Which interface member is actually chosen is implementation-dependent. Consider using a non-explicit implementation instead.

Why a warning for new scenarios?

Are you asking why we report it or why it is a warning?
The behavior matches existing behavior for instance methods and for static abstract methods (see tests above).


In reply to: 1117853635


Refers to: src/Compilers/CSharp/Test/Symbol/Symbols/StaticAbstractMembersInInterfacesTests.cs:30459 in a28883d. [](commit_id = a28883d, deletion_comment = False)

@cston
Copy link
Copy Markdown
Contributor

cston commented May 4, 2022

Are you asking why we report it or why it is a warning?

In reply to: 1117853635

Refers to: src/Compilers/CSharp/Test/Symbol/Symbols/StaticAbstractMembersInInterfacesTests.cs:30459 in a28883d. [](commit_id = a28883d, deletion_comment = False)

I meant: why not report an error rather than a warning?

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

I meant: why not report an error rather than a warning?

That is a preexisting condition/behavior. We do the same for instance methods.


In reply to: 1117959391

@AlekseyTs AlekseyTs merged commit a5f11b5 into dotnet:features/DefaultInterfaceImplementation May 4, 2022
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.

3 participants