Skip to content

Sema: Allow unavailable stored properties in swiftinterfaces #79428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5386,6 +5386,10 @@ TypeChecker::diagnosticIfDeclCannotBeUnavailable(const Decl *D) {
if (parentIsUnavailable(D))
return std::nullopt;

// Be lenient in interfaces to accomodate @_spi_available.
if (D->getDeclContext()->isInSwiftinterface())
return std::nullopt;

// Do not permit unavailable script-mode global variables; their initializer
// expression is not lazily evaluated, so this would not be safe.
if (VD->isTopLevelGlobal())
Expand Down
66 changes: 66 additions & 0 deletions test/ModuleInterface/availability-storage-macos.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// RUN: %empty-directory(%t)

// RUN: %target-swift-emit-module-interface(%t/Test.swiftinterface) %s -module-name Test -target %target-cpu-apple-macos51
// RUN: %target-swift-typecheck-module-from-interface(%t/Test.swiftinterface) -module-name Test
// RUN: %FileCheck %s < %t/Test.swiftinterface

// RUN: %target-swift-emit-module-interface(%t/TestMinInlining.swiftinterface) %s -module-name Test -target %target-cpu-apple-macos51 -target-min-inlining-version min
// RUN: %target-swift-typecheck-module-from-interface(%t/TestMinInlining.swiftinterface) -module-name Test
// RUN: %FileCheck %s < %t/TestMinInlining.swiftinterface

// REQUIRES: OS=macosx

// CHECK-LABEL: public struct StructWithProperties
public struct StructWithProperties {
// CHECK: @available(macOS, unavailable)
// CHECK-NEXT: public var unavailableComputed: Swift.Int {
// CHECK-NEXT: get
// CHECK-NEXT: }
@available(macOS, unavailable)
public var unavailableComputed: Int { 1 }

// CHECK: @available(macOS 51, *)
// CHECK-NEXT: public let introducedAtDeploymentStored: Swift.Int
@available(macOS 51, *)
public let introducedAtDeploymentStored: Int = 1

// CHECK: @available(macOS 99, *)
// CHECK-NEXT: public var introducedAfterDeploymentComputed: Swift.Int {
// CHECK-NEXT: get
// CHECK-NEXT: }
@available(macOS 99, *)
public var introducedAfterDeploymentComputed: Int { 1 }

// CHECK: @available(macOS, unavailable)
// CHECK-NEXT: public let introducedAtDeploymentSPIStored: Swift.Int
@_spi_available(macOS 51, *)
public let introducedAtDeploymentSPIStored: Int = 1
}

// CHECK-LABEL: public enum EnumWithAssociatedValues
public enum EnumWithAssociatedValues {
// CHECK: @available(macOS, unavailable)
// CHECK-NEXT: case unavailable
@available(macOS, unavailable)
case unavailable

// CHECK: @available(macOS 51, *)
// CHECK-NEXT: case introducedAtDeployment
@available(macOS 51, *)
case introducedAtDeployment

// CHECK: @available(macOS 99, *)
// CHECK-NEXT: case introducedAfterDeployment
@available(macOS 99, *)
case introducedAfterDeployment

// CHECK: @available(macOS, unavailable)
// CHECK-NEXT: case unavailableWithAssoc(Swift.Int)
@available(macOS, unavailable)
case unavailableWithAssoc(Int)

// CHECK: @available(macOS 51, *)
// CHECK-NEXT: case introducedAtDeploymentWithAssoc(Swift.Int)
@available(macOS 51, *)
case introducedAtDeploymentWithAssoc(Int)
}