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-6165] Overriding computed property with stored one is not allowed unless it is lazy #48717

Closed
swift-ci opened this issue Oct 16, 2017 · 2 comments

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Oct 16, 2017

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

md5: 301431c66b14d31c641d261286db7903

relates to:

  • SR-6980 Swift 4.1 new warning "Cannot override with a stored property"

Issue Description:

Given classes A and B like this:

class A {
    var x: Int { return 9 }
    func p() {  print(x) }
}

class B: A {
    ...
}

let v: A = B()
v.p()

overriding x in B in three different ways have the following results:

class B: A {
    // OPTION 1: FINE - prints 10
    override var x: Int { return 10 }

    // OPTION 2: ERROR - cannot override with a stored property 'x'
    override var x = 10

    // OPTION 3: FINE - prints 10
    override lazy var x = 10
}

As suggested in this answer there are cases in which overriding seems to be possible to be done without giving an error.

@belkadan
Copy link
Contributor

belkadan commented Oct 17, 2017

Oh, cute—a lazy property is implemented behind the scenes as computed, so it sneaks past the check. Fixing that would break source compatibility at this point.

Thanks for finding this.

@belkadan
Copy link
Contributor

belkadan commented Jan 11, 2018

"Fixed" in #13304 and #13335 You now get a warning in Swift 3/4 and an error in Swift 5.

@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
Projects
None yet
Development

No branches or pull requests

2 participants