Open swift-ci opened 4 years ago
@swift-ci create
I just checked this doesn't crash the compiler on Xcode 12.4
struct BankAccount {
@Lazy var balance: Int
init() {
balance = getBalanceFromDataBase() // error: 'self' used before all stored properties are initialized
}
}
Just diagnostic issue that is probably fixed on main and also 5.4 by https://github.com/apple/swift/pull/35218
So maybe we could resolve this one? cc @hborla =]
Ah! I actually suspect that this is not fixed on main. I bet the constraint system and SILGen don't know what to do for property wrapper assignment when the argument type is different between the setter and initializer due to `autoclosure`. The PR above is specific to when the wrapper has a nonmutating setter
You right, just confirmed on a near main branch the crash is fixed but incorrect diagnostic is still there...
I have been running into similar issue when using a property wrapper with init(wrappedValue: @escaping @autoclosure () -> T)
for a function argument.
file.swift
import Foundation
@propertyWrapper
struct Foo<T> {
var wrappedValue: T {
factory()
}
init(wrappedValue: @escaping @autoclosure () -> T) {
self.factory = wrappedValue
}
private let factory: () -> T
}
func bar<T>(@Foo _: @escaping @autoclosure () -> T) {}
swift file.swift
Environment
Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15) Target: x86_64-apple-darwin18.7.0Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 8fd48a17dbccfaadc96b152428b1c903Issue Description:
The follow code crashes the compiler: