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

cannot call private operators #67293

Open
tayloraswift opened this issue Jul 13, 2023 · 0 comments
Open

cannot call private operators #67293

tayloraswift opened this issue Jul 13, 2023 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@tayloraswift
Copy link
Member

tayloraswift commented Jul 13, 2023

Description

for some reason, an operator with fileprivate or greater visibility works and can be called from other methods on the same type, but if the operator is made private, it cannot be called even in places where a corresponding private method could be called.

Steps to reproduce

struct S
{
    private static
    func += (self:inout Self, characters:some StringProtocol)
    {
    }

    private static
    func add(to self:inout Self, characters:some StringProtocol)
    {
    }
}
extension S
{
    mutating
    func x()
    {
        Self.add(to: &self, characters: "abc")
    }
    mutating
    func y()
    {
        self += "abc"
    }
}
error: referencing operator function '+=' on 'RangeReplaceableCollection' requires that 'S' conform to 'RangeReplaceableCollection'
        self += "abc"
             ^
Swift.RangeReplaceableCollection:1:11: note: where 'Self' = 'S'
extension RangeReplaceableCollection {
          ^

Environment

$ swift --version
Swift version 5.8.1 (swift-5.8.1-RELEASE)
Target: x86_64-unknown-linux-gnu
@tayloraswift tayloraswift added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jul 13, 2023
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. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant