From 3d689d8fc82864652df1994a93dcecae87a24915 Mon Sep 17 00:00:00 2001 From: Allan Shortlidge Date: Tue, 21 Jun 2022 17:06:23 -0700 Subject: [PATCH] NFC: Add an entry about banning `@available` on lazy and wrapped properties. These more accurate diagnostics resulted in source breaks for some projects but the now rejected code would crash when back deployed so it was important to diagnose correctly. --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c024131acdeb..2d91c309f5d8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -488,6 +488,18 @@ _**Note:** This is in reverse chronological order, so newer entries are added to the result type provides a generalization where the callee chooses the resulting type and value. +* The compiler now correctly emits errors for `@available` attributes on stored properties with the `lazy` modifier or with attached property wrappers. Previously, the attribute was accepted on this subset of stored properties but the resulting binary would crash at runtime when type metadata was unavailable. + + ```swift + struct S { + @available(macOS 99, *) // error: stored properties cannot be marked potentially unavailable with '@available' + lazy var a: Int = 42 + + @available(macOS 99, *) // error: stored properties cannot be marked potentially unavailable with '@available' + @Wrapper var b: Int + } + ``` + * The compiler now correctly emits warnings for more kinds of expressions where a protocol conformance is used and may be unavailable at runtime. Previously, member reference expressions and type erasing expressions that used potentially unavailable conformances were not diagnosed, leading to potential crashes at runtime. ```swift