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 positive error CS9503 "Required member cannot be less visible than the containing type" for member in nested type #61527

Closed
sirduke opened this issue May 26, 2022 · 3 comments · Fixed by #61643
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:

internal class InternalOuterCsass
{
    public  class PublicInnerClass
    {
        internal required int field;
    }
}

Expected Behavior:
no error because effective accessibility of containing type is "internal"

Actual Behavior:

error CS9503: Required member 'InternalOuterCsass.PublicInnerClass.field' cannot be less visible or have a setter less visible than the containing type

@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 this to the C# 11.0 milestone May 27, 2022
@jcouv jcouv added Bug Resolution-By Design The behavior reported in the issue matches the current design and removed untriaged Issues and PRs which have not yet been triaged by a lead Resolution-By Design The behavior reported in the issue matches the current design labels May 27, 2022
@jcouv
Copy link
Member

jcouv commented May 27, 2022

I'm failing to see what the error protects in this scenario. We might consider tweaking the rules a bit.

@333fred
Copy link
Member

333fred commented May 27, 2022

IMO, this is pretty analogous to how interface methods must be public in such a scenario, even though PublicInnerClass is effectively internal.

@333fred
Copy link
Member

333fred commented Jun 1, 2022

It turned out to be easier to fix #61528 by specifying in terms of effective visibility, which changes the behavior in this bug as requested.

333fred added a commit to 333fred/roslyn that referenced this issue Jun 1, 2022
@333fred 333fred added the 4 - In Review A fix for the issue is submitted for review. label Jun 1, 2022
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.
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

Successfully merging a pull request may close this issue.

4 participants