Allow abstract and sealed modifiers on static methods/properties/events in interfaces.#52228
Conversation
…events in interafces. Related to dotnet#52202.
|
@333fred, @RikkiGibson, @dotnet/roslyn-compiler Please review. |
| { | ||
| var defaultAccess = DeclarationModifiers.Private; | ||
| // PROTOTYPE(StaticAbstractMembersInInterfaces): Do we need to check the lack of access modifier in an interface against language version? | ||
| // See https://github.com/dotnet/roslyn/issues/52202 |
There was a problem hiding this comment.
IMO I agree with Jared on the issue, this feels like a bug fix. #Closed
| var requiredVersionArgument = new CSharpRequiredLanguageVersion(requiredVersion); | ||
| var availableVersionArgument = availableVersion.ToDisplayString(); | ||
|
|
||
| reportModifier(result, DeclarationModifiers.Abstract, location, diagnostics, requiredVersionArgument, availableVersionArgument); |
There was a problem hiding this comment.
Nit: this reads a bit awkwardly. I think it would be more clear if you just checked which of the flags to report up front, rather than appearing to report both modifiers (until the reader goes and reads the body of reportModifier and pieces it together with the previous logic that ensures only one will be reported). #WontFix
There was a problem hiding this comment.
I think it would be more clear if you just checked which of the flags to report up front, rather than appearing to report both modifiers (until the reader goes and reads the body of reportModifier and pieces it together with the previous logic that ensures only one will be reported).
It sounds like you are suggesting to move the bit test out from the shared helper to here. I do not think this is the right thing to do. Also, I believe it is pretty clear that we can get here in a situation when only one of the bits is set (that is even ignoring the code that conditionally clears the DeclarationModifiers.Sealed bit above). So, it shoudl be obvious that this code doesn't report both modifiers all the time.
In reply to: 604286766 [](ancestors = 604286766)
This feels odd to me, and somewhat goes back to the same argument about Refers to: src/Compilers/CSharp/Test/Symbol/Symbols/StaticAbstractMembersInInterfacesTests.cs:171 in 1cd7bb4. [](commit_id = 1cd7bb4, deletion_comment = False) |
This error feels a bit wrong. The equivalent instance method error is Refers to: src/Compilers/CSharp/Test/Symbol/Symbols/StaticAbstractMembersInInterfacesTests.cs:95 in 1cd7bb4. [](commit_id = 1cd7bb4, deletion_comment = False) |
I think it would be useful to validate that Refers to: src/Compilers/CSharp/Test/Symbol/Symbols/StaticAbstractMembersInInterfacesTests.cs:1079 in 1cd7bb4. [](commit_id = 1cd7bb4, deletion_comment = False) |
|
Done review pass (commit 1). A couple of minor comments. |
I am not sure I am following. The behavior is consistent with instance methods today (the method is not virtual): In reply to: 810441501 [](ancestors = 810441501) Refers to: src/Compilers/CSharp/Test/Symbol/Symbols/StaticAbstractMembersInInterfacesTests.cs:171 in 1cd7bb4. [](commit_id = 1cd7bb4, deletion_comment = False) |
I believe the error is sufficiently good, it is intuitively clear that removing the modifier is the way out. If we get feedback from real users, we can improve it in the future. In reply to: 810444187 [](ancestors = 810444187) Refers to: src/Compilers/CSharp/Test/Symbol/Symbols/StaticAbstractMembersInInterfacesTests.cs:95 in 1cd7bb4. [](commit_id = 1cd7bb4, deletion_comment = False) |
Well, In reply to: 810504598 [](ancestors = 810504598,810441501) Refers to: src/Compilers/CSharp/Test/Symbol/Symbols/StaticAbstractMembersInInterfacesTests.cs:171 in 1cd7bb4. [](commit_id = 1cd7bb4, deletion_comment = False) |
|
@RikkiGibson, @dotnet/roslyn-compiler Please review, need a second sign-off. |
1 similar comment
|
@RikkiGibson, @dotnet/roslyn-compiler Please review, need a second sign-off. |
| { | ||
| var source1 = | ||
| @" | ||
| class C1 |
There was a problem hiding this comment.
Was this meant to be a struct? #Resolved
There was a problem hiding this comment.
Was this meant to be a struct?
Good catch, I'll adjust this in th enext PR.
In reply to: 606004921 [](ancestors = 606004921)
Spec: https://github.com/dotnet/csharplang/blob/9a0dddbf0643993db0da8f48436f2aac60bc20b1/proposals/statics-in-interfaces.md
Related to #52202.
Relevant quotes from the spec:
Abstract virtual members
Static interface members other than fields are allowed to also have the
abstractmodifier. Abstract static members are not allowed to have a body (or in the case of properties, the accessors are not allowed to have a body).Explicitly non-virtual static members
For symmetry with non-virtual instance members, static members should be allowed an optional
sealedmodifier, even though they are non-virtual by default: