From 6f0ca77ce8b003c681124bdb70f11e3d1aff8edc Mon Sep 17 00:00:00 2001 From: Ben Leggiero Date: Thu, 30 Jul 2020 11:55:47 -0600 Subject: [PATCH] #20: Only allow @Lazy property wrapper in Swift 5.3+ --- Sources/LazyContainers/LazyContainers.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sources/LazyContainers/LazyContainers.swift b/Sources/LazyContainers/LazyContainers.swift index e2acb82..d1bdf5b 100644 --- a/Sources/LazyContainers/LazyContainers.swift +++ b/Sources/LazyContainers/LazyContainers.swift @@ -217,6 +217,13 @@ public struct Lazy: LazyContainer { /// Same as `init(initializer:)`, but allows you to use property wrapper andor autoclosure semantics /// /// - Parameter initializer: The closure that will be called the very first time a value is needed + @available(swift, // https://github.com/RougeWare/Swift-Lazy-Patterns/issues/20 + introduced: 5.3, + message: """ + Due to changes introduced in Swift 5.3, property wrappers can now be passed their initial value lazily, through the language assignment syntax. This initializer requires that behavior to work properly. + For Swift 5.2.x and earlier, I recommend you don't use `Lazy` as a property wrapper, since Swift 5.2.x property wrappers can't guarantee lazy evaluation. + This is a real downer for me, but at least it appears to have been a fixable bug, rather than a problem with the core feature itself. + """) public init(wrappedValue initializer: @autoclosure @escaping Initializer) { self.init(initializer: initializer) }