mirror of
https://github.com/apple/swift.git
synced 2026-10-10 13:50:43 +02:00
Synthesis of `init(rawValue:)` and `rawValue` for enums conforming to `RawRepresentable` already handled enum elements with platform availability restrictions but needed to be updated to custom domain restrictions. This change also replaces the SILGen tests for `RawRepresentable` availability with `-print-ast` tests that check the synthesized bodies of the derived `RawRepresentable`, `Equatable`, and `Hashable` members directly. The new tests are more comprehensive, both in their coverage of interesting cases, but also in the completeness of the output that they check, while also being easier to understand and maintain. Resolves rdar://184726675.
59 lines
2.1 KiB
Swift
59 lines
2.1 KiB
Swift
// DEFINE: %{args} = \
|
|
// DEFINE: -module-name main \
|
|
// DEFINE: -enable-experimental-feature CustomAvailability \
|
|
// DEFINE: -define-enabled-availability-domain EnabledDomain \
|
|
// DEFINE: -define-disabled-availability-domain DisabledDomain \
|
|
// DEFINE: -define-dynamic-availability-domain DynamicDomain
|
|
|
|
// RUN: %target-swift-emit-sil %s -verify -Onone %{args} > %t.sil
|
|
// RUN: %FileCheck %s < %t.sil
|
|
// RUN: %FileCheck %s --check-prefix=NEGATIVE < %t.sil
|
|
|
|
// REQUIRES: swift_feature_CustomAvailability
|
|
|
|
// The derived members of a raw representable enum must not mention a case that
|
|
// can never be reached at runtime, even when optimizations are disabled.
|
|
// Otherwise the raw values of the cases that a disabled domain hides would be
|
|
// recoverable from the binary. No case below shares a name with another as a
|
|
// substring, so that each check below matches exactly one case.
|
|
|
|
public enum E: String {
|
|
case alwaysAvailable
|
|
|
|
@available(EnabledDomain)
|
|
case introducedByEnabled
|
|
|
|
@available(EnabledDomain, unavailable)
|
|
case hiddenByEnabled
|
|
|
|
@available(DisabledDomain)
|
|
case introducedByDisabled
|
|
|
|
@available(DisabledDomain, unavailable)
|
|
case hiddenByDisabled
|
|
|
|
@available(DynamicDomain)
|
|
case introducedByDynamic
|
|
|
|
@available(DynamicDomain, unavailable)
|
|
case hiddenByDynamic
|
|
}
|
|
|
|
// The reachable cases keep their raw values. A case that a dynamic domain
|
|
// restricts is reachable, because the domain may be enabled at runtime.
|
|
|
|
// CHECK-DAG: string_literal utf8 "alwaysAvailable"
|
|
// CHECK-DAG: string_literal utf8 "introducedByEnabled"
|
|
// CHECK-DAG: string_literal utf8 "hiddenByDisabled"
|
|
// CHECK-DAG: string_literal utf8 "introducedByDynamic"
|
|
// CHECK-DAG: string_literal utf8 "hiddenByDynamic"
|
|
|
|
// A case that an enabled domain marks unavailable, and a case that only a
|
|
// disabled domain introduces, can never be reached. Neither the raw value nor a
|
|
// reference to the case may appear in any function. The label below skips the
|
|
// declaration listing that precedes the functions, which names every case.
|
|
|
|
// NEGATIVE-LABEL: sil @main :
|
|
// NEGATIVE-NOT: hiddenByEnabled
|
|
// NEGATIVE-NOT: introducedByDisabled
|