Skip to content

CS0103 Triggers for nameof-expression inside extension property #81496

@Abrynos

Description

@Abrynos

Version Used: dotnet 10.0.100

Steps to Reproduce:

Create any extension property and use nameof() inside the getter or setter.

public static class Test {
  extension(string str)
  {
    public void SomeMethod() => Console.WriteLine(nameof(SomeMethod)); // this works

    public bool SomeProp
    {
      get => Console.WriteLine(nameof(SomeProp) + str); // this does not
      set => Console.WriteLine(nameof(SomeProp) + value); // this does not
    }

    public string SomeOtherProp => nameof(get_SomeOtherProp); // this works for some reason

    public string OneMoreProp => nameof(OneMoreProp); // again this does not
  }
}

Diagnostic Id: CS0103 - "The name 'SomeProp' does not exist in the current context"

Expected Behavior: Compilation succeeds

Actual Behavior: Compilation fails

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions