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-7980] Protocol inheritance with adding mutating keyword to the existing property #50514

Open
purpleblues opened this issue Jun 12, 2018 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@purpleblues
Copy link

Previous ID SR-7980
Radar None
Original Reporter @purpleblues
Type Bug
Environment

Xcode 10, Swift 4.2

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 6e3fa72d7ffc426051b8986f44b6f4d3

Issue Description:

When I inherit a protocol adding mutating keyword to the property with the same name from the parent protocol, I can't create a concrete type even there's no compile error for the protocols.
Check out this code:

protocol FooProtocol {
    var value: Int { get }
}
protocol MutatingFooProtocol: FooProtocol {
    var value: Int { mutating get }
}
// no compile error so far.
struct Bar: MutatingFooProtocol {
    private var storage: Int

    var value: Int {
        mutating get {
            self.storage += 1
            return self.storage
        }
    }
}

This produces compile error that Bar is not conforming to protocol FooProtocol. but adding non mutating var value: Int does not solve the problem. It creates another compile error `Invalid redeclaration of value.

I think inheriting same property name with adding mutating attribute should not be allowed from the first place.

@belkadan
Copy link
Contributor

cc @huonw

@belkadan
Copy link
Contributor

Probably a little too much for a starter bug, huh.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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

2 participants