Files
swift-mirror/test/ModuleInterface/availability-expansion.swift
Kyle 2edc61d3f1 [AST] Coalesce repeated availability domains when printing attributes (#93418)
## Motivation

Close #93415

## Summary

Separate `@available` attributes for the same platform are accepted in
source, but interface emission combines them into an invalid attribute
with duplicate platform entries.

Coalesce short-form availability attributes by domain, retaining the
greatest introduction version and preserving platform order. This
supports combining a shared availability macro such as `MyLib_v1_0` with
a stricter requirement on one platform.

## Test

Add regression coverage for the macro case in both attribute orders,
repeated versions, long and mixed forms, overlapping platform groups,
platform aliases, and preservation of deprecation information.
2026-10-22 14:11:55 +08:00

64 lines
2.4 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: %target-swift-emit-module-interface(%t/Test.swiftinterface) %s \
// RUN: -define-availability "_iOS8Aligned:macOS 10.10, iOS 8.0" \
// RUN: -define-availability "_iOS9Aligned:macOS 10.11, iOS 9.0" \
// RUN: -define-availability "_iOS9:iOS 9.0" \
// RUN: -define-availability "_macOS10_11:macOS 10.11" \
// RUN: -define-availability "_myProject 1.0:macOS 10.11" \
// RUN: -define-availability "_myProject 2.5:macOS 10.12" \
// RUN: -define-availability "_emptyMacro:*" \
// RUN: -define-availability "MyLib_v1_0:iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0"
// RUN: %target-swift-typecheck-module-from-interface(%t/Test.swiftinterface)
// RUN: %FileCheck %s < %t/Test.swiftinterface
@available(_iOS8Aligned, *)
public func onMacOS10_10() {}
// CHECK: @available(macOS 10.10, iOS 8.0, *)
// CHECK-NEXT: public func onMacOS10_10
@available(_iOS9Aligned, *)
public func onMacOS10_11() {}
// CHECK: @available(macOS 10.11, iOS 9.0, *)
// CHECK-NEXT: public func onMacOS10_11()
@available(_iOS9, _macOS10_11, tvOS 11.0, *)
public func composed() {}
// CHECK: @available(iOS 9.0, macOS 10.11, tvOS 11.0, *)
// CHECK-NEXT: public func composed()
@available(_myProject 1.0, *)
public func onMyProjectV1() {}
// CHECK: @available(macOS 10.11, *)
// CHECK-NEXT: public func onMyProjectV1
@available(_myProject 2.5, *)
public func onMyProjectV2_5() {}
// CHECK: @available(macOS 10.12, *)
// CHECK-NEXT: public func onMyProjectV2_5
@available(_emptyMacro, *)
public func emptyMacro() {}
// CHECK-NOT: @available
// CHECK-NEXT: public func emptyMacro()
@_specialize(exported: true, availability: SwiftStdlib 5.1, *; where T == Int)
public func testSemanticsAvailability<T>(_ t: T) {}
// CHECK: @_specialize(exported: true, kind: full, availability: macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *; where T == Swift::Int)
// CHECK-NEXT: public func testSemanticsAvailability
// A library's availability macro can overlap with an explicit platform
// requirement, regardless of which attribute appears first.
@available(macOS 15.0, *)
@available(MyLib_v1_0, *)
public func api() {}
// CHECK: @available(macOS 15.0, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
// CHECK-NEXT: public func api()
@available(MyLib_v1_0, *)
@available(macOS 15.0, *)
public func apiWithMacroFirst() {}
// CHECK-NEXT: @available(iOS 13.0, macOS 15.0, tvOS 13.0, watchOS 6.0, *)
// CHECK-NEXT: public func apiWithMacroFirst()