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-8676] Swift compiler doesn't infer "class only protocol" from generic where clause #51190

Closed
swift-ci opened this issue Aug 31, 2018 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-8676
Radar None
Original Reporter viktart (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 47a3ac0c7848378bcee028764cdee97d

duplicates:

  • SR-5581 Proper support for protocol 'where' clause with constraints on 'Self'

Issue Description:

The following code generates error:

error: cannot assign to property: 'self' is immutable

    **x = 1**
class MyClass { }


protocol MyProtocol where Self: MyClass {
    var x: Int { get set }
    
    func mutatingFunc()
}


extension MyProtocol {
    func mutatingFunc() {
        x = 1
    }
}

A workaround is to change protocol definition:

protocol MyProtocol: class where Self: MyClass {

but in this case you get the warning:

Redundant constraint 'Self' : 'AnyObject'

@belkadan
Copy link
Contributor

belkadan commented Sep 1, 2018

cc @slavapestov

@slavapestov
Copy link
Member

This works on master, but you have to write 'protocol MyProtocol : MyClass' instead of 'where Self : MyClass'.

@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

3 participants