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-7368] Bugs of self-referencing Default Property Values in subclasses #49916

Closed
an0 mannequin opened this issue Apr 6, 2018 · 0 comments
Closed

[SR-7368] Bugs of self-referencing Default Property Values in subclasses #49916

an0 mannequin opened this issue Apr 6, 2018 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation duplicate Resolution: Duplicates another issue expressions Feature: expressions identifiers Feature: Identifiers missing warning Bug: Missing warning self Feature → expressions: The 'self' expression swift 5.6 type checker Area → compiler: Semantic analysis

Comments

@an0
Copy link
Mannequin

an0 mannequin commented Apr 6, 2018

Previous ID SR-7368
Radar None
Original Reporter @an0
Type Bug
Status Resolved
Resolution Duplicate

Attachment: Download

Environment

Xcode 9.3

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

md5: 0da77bdeedb7ef554ed87067dd965c4e

duplicates:

Issue Description:

If I understand it correctly, self-reference should not be allowed in Default Property Values. Actually such properties should not support initialization-directly-to-final-value at all and must be var instead of let because:

  • Stored properties must be initialized before super.init,

  • But self cannot be used before super.init.

However currently this code compiles:

class ViewController: UIViewController {
    let tapGR = UITapGestureRecognizer(target: self, action: #selector(handleTap))

    override func viewDidLoad() {
        super.viewDidLoad()
        print(tapGR) // <UITapGestureRecognizer: 0x6000001eff00; state = Possible; view = <UIView 0x7fba644051b0>; target= <(action=handleTapWithSender:, target=<(null) 0x0>)>>
        view.addGestureRecognizer(tapGR)
    }

    @objc private func handleTap(sender: UITapGestureRecognizer) {
        print(sender)
    }
}

but it doesn't really work: tapGR is not really connected to self, as we can see tapGR.target is null and handleTap will never be called.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added duplicate Resolution: Duplicates another issue compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis swift 5.6 expressions Feature: expressions missing warning Bug: Missing warning identifiers Feature: Identifiers self Feature → expressions: The 'self' expression labels May 2, 2023
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 diagnostics QoI Bug: Diagnostics Quality of Implementation duplicate Resolution: Duplicates another issue expressions Feature: expressions identifiers Feature: Identifiers missing warning Bug: Missing warning self Feature → expressions: The 'self' expression swift 5.6 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

1 participant