You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SR-2203 Implicit self doesn't work in initializer of lazy var
SR-4663 Bad diagnostic when missing explicit type in lazy property declaration
Issue Description:
Usually, when `self` is missing from a call within a closure, a warning is generated (unless you explicitly capture `self`). This generally holds true for closures used to initialize lazy variables.
However, I've found that some methods (possible `objc`-related) don't require `self` to compile without warnings, but they don't work as expected either, which leads to bugs that are really easy to miss and a pain to find. It would be great to have warnings in these cases.
Steps to Reproduce:
Please see the file attached. On OS X, you can just run `swift lazy_block.swift` in the Terminal (from the respective directory).
Please read the comments in the file, too.
Expected Results:
The naive expectation when I encountered the bug was that `respondsToSelector` (line 16) would be called on the instance and return `true` (but it returns `false`).
The correct expectation should be a warning/error in that line, and possibly a fix-it, leading to what I've written in line 22 (which does return/print `true`).
Actual Results:
No warning/error, but `respondsToSelector` does not return the expected result.
Notes:
This problem does not seem to occur in normal closures (see lines 51 ff). I could only reproduce this in lazy variable initializations.
This has been filed as a radar before, but I think this bug tracker offers a better chance of getting attention from the Swift team or the general community. For reference: rdar://22067698. The example has been updated/simplified, so please prefer this bug report over the radar.
The text was updated successfully, but these errors were encountered:
Attachment: Download
Environment
Verified with Apple Swift version 2.1.1 and Apple Swift version 2.2-dev
OS X 10.11.1 (15B42). Requires Foundation framework and ObjC runtime.
Additional Detail from JIRA
md5: 484aa387c639f336a3aed7547f1776b1
is duplicated by:
relates to:
self
doesn't work in initializer of lazy varIssue Description:
Usually, when `self` is missing from a call within a closure, a warning is generated (unless you explicitly capture `self`). This generally holds true for closures used to initialize lazy variables.
However, I've found that some methods (possible `objc`-related) don't require `self` to compile without warnings, but they don't work as expected either, which leads to bugs that are really easy to miss and a pain to find. It would be great to have warnings in these cases.
Steps to Reproduce:
Please see the file attached. On OS X, you can just run `swift lazy_block.swift` in the Terminal (from the respective directory).
Please read the comments in the file, too.
Expected Results:
The naive expectation when I encountered the bug was that `respondsToSelector` (line 16) would be called on the instance and return `true` (but it returns `false`).
The correct expectation should be a warning/error in that line, and possibly a fix-it, leading to what I've written in line 22 (which does return/print `true`).
Actual Results:
No warning/error, but `respondsToSelector` does not return the expected result.
Notes:
This problem does not seem to occur in normal closures (see lines 51 ff). I could only reproduce this in lazy variable initializations.
This has been filed as a radar before, but I think this bug tracker offers a better chance of getting attention from the Swift team or the general community. For reference: rdar://22067698. The example has been updated/simplified, so please prefer this bug report over the radar.
The text was updated successfully, but these errors were encountered: