Skip to content

@Lazy property wrapper is loaded eagerly #20

@gshahbazian

Description

@gshahbazian

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)
    ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions