-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Open
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfregressionswift 5.0
Description
Previous ID | SR-10668 |
Radar | None |
Original Reporter | @sindresorhus |
Type | Bug |
Environment
Swift 5
Xcode 10.2.1
macOS 10.14.4
Additional Detail from JIRA
Votes | 0 |
Component/s | Compiler |
Labels | Bug, 5.0Regression |
Assignee | @slavapestov |
Priority | Medium |
md5: 53b86198e420bf1e3f5944efa4cfaeea
Issue Description:
When upgrading from Swift 4.2 to Swift 5, I encountered a case of code that no longer compiles.
The following compiled fine in Swift 4.2 (Xcode 10.1):
func run<T, U>(_ value: T, _ block: (T) -> U) -> U {
return block(value)
}
class Fixture {}
class Foo {
lazy var a = run(Fixture()) { _ in
print(b)
}
lazy var b = run(Fixture()) { _ in
print(a)
}
}
But with Swift 5 (Xcode 10.2), I get this error:
error: value of type 'Foo' has no member 'a'
However, if I remove the `run()` usage from the `a` variable, it compiles fine:
func run<T, U>(_ value: T, _ block: (T) -> U) -> U {
return block(value)
}
class Fixture {}
class Foo {
lazy var a: Fixture = {
print(b)
return Fixture()
}()
lazy var b = run(Fixture()) { _ in
print(a)
}
}
I couldn't find anything in the release notes about this, so I'm gonna assume it's a regression in Swift 5.
I use the `run()` utility a lot in my code and it would be too bad if that pattern is no longer supported.
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfregressionswift 5.0