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-7981] self available without backticks in let initialization closure of NSObject #50515

Closed
swift-ci opened this issue Jun 12, 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

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 12, 2018

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.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added duplicate Resolution: Duplicates another issue 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

2 participants