Type of issue
Missing information
Description
V14 introduced a new cause for this error.
I'm writing text for the formal Ecma spec for the V14 feature, "Extension members," and stumbled on this in one of my tests. Consider the following code:
public static class Ex4
{
public static void MX1(this int p) { int z = p; } // OK: old-style extension method
extension(int q)
{
public static void MX2(this int p) { int z = p; } // CS0027 old-style extension method inside an extension block
public void MX3() { int z = q; } // OK: new-style extension method
}
}
By having a first parameter with the this modifier, method MX1 is recognized as an (old-style) extension method. OK! The correct way to rewrite that declaration using the V14 (new-style) is like MX3.
Writing it like MX2 generates CS0027. So although this is a method declaration, it is an old-style extension method inside a new-style extension block, and apparently that is not permitted.
Page URL
https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs0027?f1url=%3FappId%3Droslyn%26k%3Dk(CS0027)
Content source URL
https://github.com/dotnet/docs/blob/main/docs/csharp/misc/cs0027.md
Document Version Independent Id
ce979e00-3708-b993-0398-fd7995c1f9ae
Platform Id
084a3d4f-6cf7-cadf-13cc-e94ea4ec83c2
Article author
@BillWagner
Metadata
- ID: 0db95a07-85cc-1385-3249-2db88b0dbb34
- PlatformId: 084a3d4f-6cf7-cadf-13cc-e94ea4ec83c2
- Service: dotnet-csharp
- Sub-service: errors-warnings
Related Issues
Associated WorkItem - 631434
Type of issue
Missing information
Description
V14 introduced a new cause for this error.
I'm writing text for the formal Ecma spec for the V14 feature, "Extension members," and stumbled on this in one of my tests. Consider the following code:
By having a first parameter with the
thismodifier, methodMX1is recognized as an (old-style) extension method. OK! The correct way to rewrite that declaration using the V14 (new-style) is likeMX3.Writing it like
MX2generates CS0027. So although this is a method declaration, it is an old-style extension method inside a new-style extension block, and apparently that is not permitted.Page URL
https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs0027?f1url=%3FappId%3Droslyn%26k%3Dk(CS0027)
Content source URL
https://github.com/dotnet/docs/blob/main/docs/csharp/misc/cs0027.md
Document Version Independent Id
ce979e00-3708-b993-0398-fd7995c1f9ae
Platform Id
084a3d4f-6cf7-cadf-13cc-e94ea4ec83c2
Article author
@BillWagner
Metadata
Related Issues
Associated WorkItem - 631434