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-697] Compiler wants protocol extension method to be both private and public at the same time #43312

Closed
michelf opened this issue Feb 9, 2016 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@michelf
Copy link

michelf commented Feb 9, 2016

Previous ID SR-697
Radar rdar://problem/21380336
Original Reporter @michelf
Type Bug
Status Resolved
Resolution Cannot Reproduce
Additional Detail from JIRA
Votes 2
Component/s Compiler
Labels Bug
Assignee None
Priority

md5: ce2ff1f56579c5c8afa230f4378fb4af

is duplicated by:

  • SR-4697 Damned if you do... (access control)

Issue Description:

With the following code, the Swift compiler complains that func test() in the extension of Y needs to be public because it implements public protocol X, but also want it to be private because protocol Y is private. I think the correct thing to do is to allow public visibility in the extension when it implements a method from a public protocol.

public protocol X {
    func test()
}
private protocol Y: X {
}
extension Y {
    public func test() {}
}
public class Z: X, Y {
}

Below: the two error messages from a playground in Xcode 7.2.1 (7C1002) for the code above. Note that applying the first fix-it causes a new error accompanied by a new fix-it proposing a return to the version above (creating a loop). The second fix-it below generates invalid code with two public attributes before func.

...playground364.swift:7:2: warning: declaring a public instance method for a private protocol
        public func test() {}
        ^~~~~~
        private
...playground364.swift:7:14: error: method 'test()' must be declared public because it matches a requirement in public protocol 'X'
        public func test() {}
                    ^
               public 
@belkadan
Copy link
Contributor

belkadan commented Feb 9, 2016

We actually can't do that yet, because calling the method in the extension requires knowing something about Y. But you're not the first to ask for it.

@CodaFi
Copy link
Member

CodaFi commented Dec 14, 2016

This was resolved in the move to fileprivate stuff when we dropped the "greater than or equal to" access requirement for member decls.

@belkadan
Copy link
Contributor

I think there's still a cross-module issue, since the symbol won't be public.

@tkrajacic
Copy link

This can be closed I guess. There are no more fixits in a playground when testing the code above.

@CodaFi
Copy link
Member

CodaFi commented Nov 18, 2020

No longer reproduces in Xcode 12.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

4 participants