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-4395] Incomplete initialization of self results in confusing error messages with @autoclosure functions #46974

Closed
huonw mannequin opened this issue Mar 28, 2017 · 0 comments
Assignees
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

Comments

@huonw
Copy link
Mannequin

huonw mannequin commented Mar 28, 2017

Previous ID SR-4395
Radar rdar://problem/30324153
Original Reporter @huonw
Type Bug
Status Resolved
Resolution Duplicate
Environment

Swift 3.1

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI
Assignee @xedin
Priority Medium

md5: 5915746317b41ebad398b7259dc02d0b

duplicates:

  • SR-944 Cannot use 'self' in RHS of && before all properties are initialized

Issue Description:

The following code compiles fine

class Foo {
    var a: Int
    var b: Int

    init() {
        self.a = 0

        if self.a > 0 {}
        self.b = self.a
    }
}

But if one decides that the if condition needs to do more:

class Foo {
    var a: Int
    var b: Int

    init() {
        self.a = 0

        if true && self.a > 0 {}
        self.b = self.a
    }
}

ERROR at line 8, col 20: 'self' captured by a closure before all members were initialized
        if true && self.a > 0 {}
                   ^
NOTE at line 3, col 9: 'self.b' not initialized
    var b: Int
        ^

This error confusing for a few reasons: there's no closures in the source (just the @autoclosure second argument of &&), and the reverse works fine (self.a > 0 && true).

(Prompted by http://stackoverflow.com/questions/43074430/guard-condition-provokes-compiler-error-that-talks-about-closure )

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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
Projects
None yet
Development

No branches or pull requests

0 participants