-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed as duplicate of#47136
Closed as duplicate of#47136
Copy link
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of ImplementationexpressionsFeature: expressionsFeature: expressionsidentifiersFeature: IdentifiersFeature: Identifiersmissing warningBug: Missing warningBug: Missing warningselfFeature → expressions: The 'self' expressionFeature → expressions: The 'self' expressionswift 5.6type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis
Description
| 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
selfcannot be used beforesuper.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.
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of ImplementationexpressionsFeature: expressionsFeature: expressionsidentifiersFeature: IdentifiersFeature: Identifiersmissing warningBug: Missing warningBug: Missing warningselfFeature → expressions: The 'self' expressionFeature → expressions: The 'self' expressionswift 5.6type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis