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-2329] self unavailable in closures to initialize lazy properties unless type specified #44936

Closed
5sw opened this issue Aug 12, 2016 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@5sw
Copy link

5sw commented Aug 12, 2016

Previous ID SR-2329
Radar None
Original Reporter @5sw
Type Bug
Status Resolved
Resolution Duplicate
Environment

swift-DEVELOPMENT-SNAPSHOT-2016-08-07-a.xctoolchain on Mac OS X 10.11.6

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

md5: b81de81480504c635ad77aba95f15343

duplicates:

  • SR-2203 Implicit self doesn't work in initializer of lazy var

relates to:

  • SR-2616 'lazy' keyword results in "Type of expression is ambiguous without more context"

Issue Description:

Self is unavailable in closures used to initialize lazy properties unless the type of that property is explicitly stated. Consider this code:

class Test {
   let c = "Test"
   lazy var a : String = { self.c }()
   lazy var b = { self.c }()
}

The closure used to initialize a works fine. But for the closure for b we get the error message "error: use of unresolved identifier 'self'".

This also happens if the type of the closure is not needed to infer the type of the lazy property, for example as in

class Test {
   lazy var a : String = something { print(self) }
   lazy var b = something { print(self) }
}
func something( _ closure : () -> () ) -> String { ... }

Here again a is fine, but in b the error message appears.

@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.
Projects
None yet
Development

No branches or pull requests

1 participant