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-4663] Bad diagnostic when missing explicit type in lazy property declaration #47240

Closed
NachoSoto opened this issue Apr 21, 2017 · 7 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

@NachoSoto
Copy link
Contributor

Previous ID SR-4663
Radar rdar://problem/31762378
Original Reporter @NachoSoto
Type Bug
Status Resolved
Resolution Done
Environment

Swift version 3.1 (swiftlang-802.0.53 clang-802.0.42)
Swift version 4.0 (swiftlang-900.0.43 clang-900.0.22.8)

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

md5: 19adca2756e1fcca25bac4fce084325d

relates to:

  • SR-2203 Implicit self doesn't work in initializer of lazy var
  • SR-48 Create warning for missing self in lazy var initialization

Issue Description:

The following code:

class B {
    init(x: String) {}
}

class C {
    init(x: String) {
        self.x = x
    }

    private lazy var b = {
        return B(x: self.x)
    }()

    private let x: String
}

Produces:

error: repl.swift:26:21: error: use of unresolved identifier 'self'
        return B(x: self.x)
                    ^~~~

Alternatively, if C inherits NSObject:

import Foundation

class B {
    init(x: String) {}
}

class A {}

class C: NSObject {
    init(x: String) {
        self.x = x
    }

    private lazy var b = {
        return B(x: self.x)
    }()

    private let x: String
}

That leads to an even worse diagnostic:

error: repl.swift:30:21: error: value of type '(NSObject) -> () -> C' has no member 'x'
        return B(x: self.x)
                    ^~~~ ~

In both cases the right diagnostic would have been "missing explicit type declaration" or something like that.

@jckarter
Copy link
Member

@swift-ci create

@belkadan
Copy link
Contributor

Use of 'self' in lazy properties is still all messed up.

@slavapestov
Copy link
Member

#9920

@NachoSoto
Copy link
Contributor Author

I just ran the same code in Swift 4.0 (swiftlang-900.0.43 clang-900.0.22.8) and I'm getting the same result.

@jckarter
Copy link
Member

@NachoSoto Is that from Xcode 9 beta 1, or a snapshot toolchain? The Xcode beta was cut about three weeks ago so may have missed the fix.

@NachoSoto
Copy link
Contributor Author

Xcode 9 beta 1. I misread the date on @slavapestov's comment, sorry, I thought this had been fixed longer ago.
I'll verify on beta 2.

@slavapestov
Copy link
Member

You can try a recent 4.0 snapshot, it should be there.

@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

4 participants