Skip to content

extension block doesn't allow extern #78572

@jolaquai

Description

@jolaquai

Version Used:

.NET SDK:
 Version:           10.0.100-preview.4.25258.110
 Commit:            c22dcd0c7a
 Workload version:  10.0.100-manifests.e9b6aa6e
 MSBuild version:   17.15.0-preview-25258-110+c22dcd0c7

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.26200
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\10.0.100-preview.4.25258.110\

Microsoft Visual Studio Community 2022 (64-bit) - Preview Version 17.14.0 Preview 7.0

Steps to Reproduce:

  1. Create any project type
  2. Set net10.0 and preview
  3. Write an extension block method that requires extern, something like:
extension(System.IO.MemoryStream stream)
{
    [UnsafeAccessor(UnsafeAccessorKind.Field)]
    public extern ref byte[] _buffer();
}
  1. Attempt a build.

Diagnostic Ids:

CS0106: The modifier 'extern' is not valid for this item
CS0501: 'Program.extension(MemoryStream)._buffer()' must declare a body because it is not marked abstract, extern, or partial

Expected Behavior: The code compiles.

Actual Behavior: extern is complained about and the build fails. I'm assuming it's because it's not technically static anymore, but even adding it doesn't help (and would prevent use of the extension parameter if it did).

I'm assuming this is the case for a few more "niche" features in the context of extensions. (And yeah, granted, the example I chose is a bit silly.)

"Legacy" implementation method syntax compiles fine:

[UnsafeAccessor(UnsafeAccessorKind.Field)]
public static extern ref byte[] _buffer(this System.IO.MemoryStream stream);

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions