Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Speculative" keywords (discard, field) binding + private symbols in base type #60836

Open
controlflow opened this issue Apr 19, 2022 · 1 comment
Assignees
Milestone

Comments

@controlflow
Copy link

Version Used:

main branch 19.04.2022
features/semi-auto-props branch 19.04.2022

Steps to Reproduce:

Compile the following code:

class A {
  // all private
  private int _, field;
  private string nameof(int i) => "";
}

class B : A {
  int Property {
    get {
      var name = nameof(A); // OK
      _ = "discard"; // error, inaccessible
      return field; // error, inaccessible
    }
  }
}

https://sharplab.io/#v2:EYLgZgpghgLgrgJwgZwLTIgWwJaqnGAe1QAcFCTkAaAExAGoAfAAQCYACAQXYG8BYAFDt2AehHsoAG0nsy2AG6wIg4XMUwI7bADsY7APpV2YbBEk0A3CtkIFS9swCMABnbaomCITAAKHXuwASnYAXgA+dgAiSKsBAF9BQTZ2ACF2EC5ea392AAVyEggEGABPLKFhdgBzCD1+Csr2RQQ3D00Q1s9vH05Ai1FxAHkAaWtG/VCommxkAGMoBBoYgfYi8gQjHShZ2ZRkbGBJZQbK5gB2Y1NzfrFVhHXN9x29g6Ox9gSKz7igA===

Expected Behavior:

Compilation is OK, in class B the _ reference is a discard and field is a backing field reference.
I expect _ and field to work the same way nameof works - the compilation of B should not rely on seot of private APIs in type A.

Actual Behavior:

error CS0122: 'A._' is inaccessible due to its protection level
error CS0122: 'A.field' is inaccessible due to its protection level

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 19, 2022
@controlflow controlflow changed the title "Speculative" keywords (discard, field) binding + private symbols "Speculative" keywords (discard, field) binding + private symbols in base type Apr 19, 2022
@hez2010
Copy link

hez2010 commented Apr 19, 2022

I think _ will become a lexical keyword in the language and cannot be used as identifiers in the future.
See: dotnet/csharplang#4460

@jcouv jcouv self-assigned this Apr 21, 2022
@jcouv jcouv added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 21, 2022
@jcouv jcouv added this to the Compiler.Next milestone Apr 21, 2022
@jaredpar jaredpar modified the milestones: Compiler.Next, Backlog Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants