Skip to content

[SR-8440] Using self inside a let initializer #50962

@swift-ci

Description

@swift-ci
Previous ID SR-8440
Radar None
Original Reporter kanersan (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode 9.4.1 - Swift 4.1

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

md5: e2dca743fabfb653f26fcddaaaf02779

duplicates:

Issue Description:

Using self inside an initializer causes compiler error, which makes sense.

However, trying to use self to hookup a touchUpInside action on a UIKit object (for example UIButton) which is a let computed property doesn't cause compiler errors.

Below code is what I mean:

let someButton: UIButton = {
    let button = UIButton()
    button.addTarget(self, action: #selector(buttonTappedFunction), for: .touchUpInside)
}()

And the action doesn't work but the code compiles and runs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationexpressionsFeature: expressionsidentifiersFeature: Identifiersmissing warningBug: Missing warningselfFeature → expressions: The 'self' expressionswift 5.6type checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions