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

False negative error CS9503 "Required member cannot be less visible than the containing type" for member in nested type #61528

Closed
sirduke opened this issue May 26, 2022 · 3 comments
Assignees
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers Bug Feature - Required Members Required properties and fields
Milestone

Comments

@sirduke
Copy link

sirduke commented May 26, 2022

Version Used:
features/required-members

Steps to Reproduce:

public class Outer {
    protected class ProtectedClass {
        protected required int ProtectedProperty { get; set; }
    }
}

 class Derived : Outer {
     public void Test() {
         var p = new ProtectedClass() // error "Required member 'Outer.ProtectedClass.ProtectedProperty' must be set
         {
           // ProtectedProperty = 1 // cannot set the property because it is inaccessible
         };
     }
 }

Expected Behavior:
Error CS9503 is shown for ProtectedProperty declaration

Actual Behavior:
No error for ProtectedProperty declaration is shown but it is impossible to create instance of ProtectedClass in derived class

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels May 26, 2022
@svick svick added the Feature - Required Members Required properties and fields label May 26, 2022
@jcouv jcouv added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels May 27, 2022
@jcouv jcouv added this to the C# 11.0 milestone May 27, 2022
@Eli-Black-Work
Copy link

Dupe of #61527

@333fred
Copy link
Member

333fred commented Jun 1, 2022

No, this is not a duplicate.

@Eli-Black-Work
Copy link

Sorry, I must have been tired yesterday 😅

333fred added a commit that referenced this issue Jun 14, 2022
… enforcement (#61643)

* Calculate containing type effective accessibility for required member enforcement

Implements the spec change in dotnet/csharplang#6190. Fixes #61527 and #61528.
@333fred 333fred closed this as completed Jun 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers Bug Feature - Required Members Required properties and fields
Projects
None yet
Development

No branches or pull requests

5 participants