-
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-7981 |
| Radar | None |
| Original Reporter | benpious (JIRA User) |
| Type | Bug |
| Status | Resolved |
| Resolution | Duplicate |
Environment
Xcode 9.3.0.
Additional Detail from JIRA
| Votes | 0 |
| Component/s | Compiler |
| Labels | Bug |
| Assignee | None |
| Priority | Medium |
md5: 8bc95e194233eeaad7dd08b80e745ab5
duplicates:
Issue Description:
This code compiles. In Xcode, it even colors self as though it's a keyword.
import UIKit
class C: NSObject {
let button: UIButton = {
let button = UIButton()
button.addTarget(self,
action: #selector(f),
for: .touchUpInside)
return button
}()
@objc
func f() {
}
}But self is actually NSObject.self, which is a function.
Note that in a non-NSObject subclass, this code does not compile, with the error "error: use of unresolved identifier 'self'". So I'm guessing that the compiler currently has a hack of some sort to prevent self from referring to NSObject.self as in the class object in this context, since that would be confusing. And that that's why the compiler allows NSObject.self to not be backticked.
Note that
class C {
func self() {
}
}also doesn't compile, nor does refering to a func `self`() function without backticks, so allowing this is clearly wrong.
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