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

Fix NoAccessLevelOnExtensionDeclaration to update members inside #if blocks. #969

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

allevato
Copy link
Member

Fixes #966.

This rewrites the rule entirely to take advantage of the natural recursion of visiting the extension's children instead of trying to rewrite and replace the member list at the extension level.

I've tended to avoid the idea of writing stateful format rules like this, because pushing state down from a node to its children would normally require maintaining a stack of information. But in this case, the problem is a lot simpler because extensions can't be nested, so there's never more than one level of state to track.

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m sorry to disappoint you but nesting extensions is not a parser error. The following parsers fine

extension A {
  extension B {   
  }
}

Nested extensions only get diagnosed at type-checking time, so I think we do need to handle them…

@allevato
Copy link
Member Author

I’m sorry to disappoint you but nesting extensions is not a parser error. The following parsers fine

extension A {
  extension B {   
  }
}

Nested extensions only get diagnosed at type-checking time, so I think we do need to handle them…

Ugh, yeah, you're right.

Do you have a preference for how you'd like them handled? We could manage the stack and do the same thing for nested extensions that we would for top-level ones, or we could just ignore nested extensions because they're obviously broken.

@ahoppen
Copy link
Member

ahoppen commented Mar 21, 2025

I would just not walk into nested extensions. Leaving them as-is is probably the best thing we can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NoAccessLevelOnExtensionDeclaration doesn't apply access modifier on members guarded by #if
2 participants