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

[SR-4616] Implement SE-0169: Improve Interaction Between private Declarations and Extensions #47193

Closed
DougGregor opened this issue Apr 18, 2017 · 6 comments
Labels
access control Feature → modifiers: Access control and access levels compiler The Swift compiler in itself feature A feature request or implementation improvement swift evolution implemented Flag → feature: A feature that was approved through the Swift evolution process and implemented

Comments

@DougGregor
Copy link
Member

Previous ID SR-4616
Radar rdar://problem/31684646
Original Reporter @DougGregor
Type New Feature
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels New Feature
Assignee KingOfBrian (JIRA)
Priority Medium

md5: 12abbe7ba8ef0734efc7c5c7ba8e1fcf

Issue Description:

Proposal here:

https://github.com/apple/swift-evolution/blob/master/proposals/0169-improve-interaction-between-private-declarations-and-extensions.md

@DougGregor
Copy link
Member Author

@swift-ci create

@belkadan
Copy link
Contributor

belkadan commented Apr 19, 2017

The best implementation plan I have now is:

1. An AccessScope for a private declaration within an extension is no longer simply its DeclContext. Instead, if the enclosing type is defined in the same file, the type's declaration becomes the AccessScope. Otherwise, the last extension of the type in the file is the AccessScope. This collapses the various extensions in a file into the same AccessScope.

2. When checking if one access scope is contained within another, if the access scope is an extension, look at the base type. If it's defined in the same file, the containing access scope is the private access scope for the base type declaration as described in (1). Otherwise, it's the last extension of the base type in the current file, rather than the file in which it was defined. (If there is no such extension, move up to the next parent.) This allows the example below to compile:

struct Outer {
  struct Middle {
    struct Inner {}
  }
}
extension Outer {
  private static func foo() {}
}

extension Outer.Middle.Inner {
  func bar() {
    Outer.foo()
  }
}

I don't love this because it's a lot of extra work to determine access, but it's the best I have. An invariant here is that a parent access scope never crosses file boundaries, and the three outermost access scopes are still "the current file", "the current module", and "the world".

@rintaro
Copy link
Mannequin

rintaro mannequin commented Apr 27, 2017

Ah, I didn't know KingOfBrian (JIRA User) already took this task. Go for it.
FWIW, here's WIP branch of mine.
master...rintaro:ast-accesscope-se-169

@swift-ci
Copy link
Collaborator

Comment by Brian (JIRA)

Thanks @rintaro, things are coming along: – master...KingOfBrian:feature/SE-0169 Should have a PR in tomorrow.

@tkremenek
Copy link
Member

Pull request:

#9098

@tkremenek
Copy link
Member

Merged to `master`.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added feature A feature request or implementation access control Feature → modifiers: Access control and access levels swift evolution implemented Flag → feature: A feature that was approved through the Swift evolution process and implemented improvement and removed new feature labels Jan 27, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
access control Feature → modifiers: Access control and access levels compiler The Swift compiler in itself feature A feature request or implementation improvement swift evolution implemented Flag → feature: A feature that was approved through the Swift evolution process and implemented
Projects
None yet
Development

No branches or pull requests

5 participants