@Lazy property wrapper is loaded eagerly
This is a test that ensures the init of a class isn't run when being stored at an @Lazy property. The test fails (and matches what I saw in real world usage), which looks like the property is loaded eagerly.
import XCTest
@testable import LazyContainers
var shouldNotRun = false
class ShouldNotInit {
init() {
shouldNotRun = true
}
}
final class LazyContainersTests: XCTestCase {
@Lazy
var lazyShouldNotRun = ShouldNotInit()
func testLazyInitWithPropertyWrapper() {
XCTAssertFalse(shouldNotRun)
}
static var allTests = [
("testLazyInitWithPropertyWrapper", testLazyInitWithPropertyWrapper)
]
}
Oh wow that's definitely a bug! I'll see what I can do about this
Well this is concerning... I have reproduced your issue in Xcode 11.6, but not in Xcode 12 (Beta 3)... So maybe something changed between Swift 5.2.4 and 5.3? Gonna be hard to pin down a solution.
@gshahbazian thanks for reporting this - I've released a new version with a bodgey workaround, to be removed once Swift 5.2 support is dropped
Just realized I forgot to mark the property wrapper initializer for ResettableLazy. Whoops!
Version 6 of this package will remove support for Swift ≤5, which means that the package won't compile where this issue was present.
That means version 6 effectively "fixes" this issue by requiring a Swift version where this issue isn't present