Enable declaration, implementation(in non-interfaces) and consumption of virtual static members.#60965
Conversation
333fred
left a comment
There was a problem hiding this comment.
Reviewed everything except StaticAbstractMembersInInterfacesTests.cs. Will get to that tomorrow.
…terfaceImplementation_102
…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. | |||
There was a problem hiding this comment.
Should we update this and other tests that use C# 9 to 10? #Resolved
There was a problem hiding this comment.
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.
333fred
left a comment
There was a problem hiding this comment.
LGTM (commit 9). Future reviews, I recommend turning off whitespace to avoid a decent chunk of changes in some of the test files.
|
@jcouv, @dotnet/roslyn-compiler For the second review. In reply to: 1113626786 |
|
@dotnet/roslyn-compiler For the second review. In reply to: 1114895031 |
| MessageID.IDS_FeatureStaticAbstractMembersInInterfaces.Localize(), | ||
| availableVersion.GetValueOrDefault().ToDisplayString(), | ||
| new CSharpRequiredLanguageVersion(requiredVersion)); | ||
| } |
There was a problem hiding this comment.
Please consider extracting this to a local function that can be reused for IDS_DefaultInterfaceImplementation above. #Resolved
There was a problem hiding this comment.
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 { }); | |||
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Why check this rather than calling
Suppresses extra diagnostics for "abstract virtual" case
There was a problem hiding this comment.
I think there is a dedicated error reported for this case elsewhere.
Why is In reply to: 1116901341 Refers to: src/Compilers/CSharp/Test/Symbol/Symbols/DefaultInterfaceImplementationTests.cs:174 in a28883d. [](commit_id = a28883d, deletion_comment = False) |
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) |
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) |
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) |
Why is In reply to: 1117832578 Refers to: src/Compilers/CSharp/Test/Symbol/Symbols/StaticAbstractMembersInInterfacesTests.cs:21698 in a28883d. [](commit_id = a28883d, deletion_comment = False) |
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> |
There was a problem hiding this comment.
Please also test with Shared only, not Overridable.
Isn't this the previous test?
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) |
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? |
That is a preexisting condition/behavior. We do the same for instance methods. In reply to: 1117959391 |
https://github.com/dotnet/csharplang/blob/main/proposals/static-abstracts-in-interfaces.md
Test plan: #60968