Skip to content

Commit e1995ce

Browse files
committed
AST: Fix nesting of unavailable AvailabilityContexts.
1 parent 2ba37da commit e1995ce

File tree

2 files changed

+40
-19
lines changed

2 files changed

+40
-19
lines changed

lib/AST/AvailabilityContext.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,21 @@ bool AvailabilityContext::PlatformInfo::constrainUnavailability(
3939
if (!unavailablePlatform)
4040
return false;
4141

42-
// Check whether the decl's unavailability reason is the same.
43-
if (IsUnavailable && UnavailablePlatform == *unavailablePlatform)
44-
return false;
42+
if (IsUnavailable) {
43+
// Universal unavailability cannot be refined.
44+
if (UnavailablePlatform == PlatformKind::none)
45+
return false;
4546

46-
// Check whether the decl's unavailability reason is more specific.
47-
if (*unavailablePlatform != PlatformKind::none &&
48-
inheritsAvailabilityFromPlatform(*unavailablePlatform,
49-
UnavailablePlatform))
50-
return false;
47+
// There's nothing to do if the platforms already match.
48+
if (UnavailablePlatform == *unavailablePlatform)
49+
return false;
50+
51+
// The new platform must be more restrictive.
52+
if (*unavailablePlatform != PlatformKind::none &&
53+
inheritsAvailabilityFromPlatform(*unavailablePlatform,
54+
UnavailablePlatform))
55+
return false;
56+
}
5157

5258
IsUnavailable = true;
5359
UnavailablePlatform = *unavailablePlatform;

test/Sema/availability_refinement_contexts.swift

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -319,23 +319,38 @@ func unavailableOnMacOS() {
319319
let x = 1
320320
}
321321

322-
// CHECK-NEXT: {{^}} (decl_implicit version=50 deprecated decl=deprecatedOnMacOS()
323-
// CHECK-NEXT: {{^}} (decl_implicit version=50 deprecated decl=x
324-
325-
@available(macOS, deprecated)
326-
func deprecatedOnMacOS() {
327-
let x = 1
328-
}
329-
330322
// CHECK-NEXT: {{^}} (decl_implicit version=50 decl=extension.SomeEnum
331323
// CHECK-NEXT: {{^}} (decl_implicit version=50 unavailable=macOS decl=extension.SomeEnum
332-
// CHECK-NEXT: {{^}} (decl_implicit version=50 unavailable=macOS decl=propertyInUnavailableExtension
333-
// CHECK-NEXT: {{^}} (decl version=52 unavailable=macOS decl=propertyInUnavailableExtension
324+
// CHECK-NEXT: {{^}} (decl_implicit version=50 unavailable=macOS decl=availableMacOS_52
325+
// CHECK-NEXT: {{^}} (decl version=52 unavailable=macOS decl=availableMacOS_52
326+
// CHECK-NEXT: {{^}} (decl_implicit version=50 unavailable=* decl=neverAvailable()
334327

335328
@available(macOS, unavailable)
336329
extension SomeEnum {
337330
@available(OSX 52, *)
338-
var propertyInUnavailableExtension: Int { 1 }
331+
var availableMacOS_52: Int { 1 }
332+
333+
@available(macOSApplicationExtension, unavailable)
334+
func unavailableInAppExtensions() {}
335+
336+
@available(*, unavailable)
337+
func neverAvailable() {}
338+
}
339+
340+
// CHECK-NEXT: {{^}} (decl_implicit version=50 unavailable=* decl=NeverAvailable
341+
342+
@available(*, unavailable)
343+
struct NeverAvailable {
344+
@available(macOS, unavailable)
345+
func unavailableOnMacOS() {}
346+
}
347+
348+
// CHECK-NEXT: {{^}} (decl_implicit version=50 deprecated decl=deprecatedOnMacOS()
349+
// CHECK-NEXT: {{^}} (decl_implicit version=50 deprecated decl=x
350+
351+
@available(macOS, deprecated)
352+
func deprecatedOnMacOS() {
353+
let x = 1
339354
}
340355

341356
// CHECK-NEXT: {{^}} (decl version=51 decl=FinalDecl

0 commit comments

Comments
 (0)