Skip to content

Commit eedb634

Browse files
committed
Sema: Always query abstract syntax decls for availability attributes.
1 parent e1995ce commit eedb634

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,7 @@ static const AvailableAttr *getActiveAvailableAttribute(const Decl *D,
348348

349349
/// Returns true if there is any availability attribute on the declaration
350350
/// that is active on the target platform.
351-
static bool hasActiveAvailableAttribute(Decl *D,
352-
ASTContext &AC) {
351+
static bool hasActiveAvailableAttribute(const Decl *D, ASTContext &AC) {
353352
return getActiveAvailableAttribute(D, AC);
354353
}
355354

@@ -718,9 +717,13 @@ class TypeRefinementContextBuilder : private ASTWalker {
718717
return nullptr;
719718
}
720719

721-
const AvailabilityContext getEffectiveAvailabilityForDeclSignature(Decl *D) {
720+
const AvailabilityContext
721+
getEffectiveAvailabilityForDeclSignature(const Decl *D) {
722722
auto EffectiveIntroduction = AvailabilityRange::alwaysAvailable();
723723

724+
// Availability attributes are found abstract syntax decls.
725+
D = abstractSyntaxDeclForAvailableAttribute(D);
726+
724727
// As a special case, extension decls are treated as effectively as
725728
// available as the nominal type they extend, up to the deployment target.
726729
// This rule is a convenience for library authors who have written
@@ -754,7 +757,7 @@ class TypeRefinementContextBuilder : private ASTWalker {
754757
/// are not constrained since they appear in the interface of the module and
755758
/// may be consumed by clients with lower deployment targets, but there are
756759
/// some exceptions.
757-
bool shouldConstrainSignatureToDeploymentTarget(Decl *D) {
760+
bool shouldConstrainSignatureToDeploymentTarget(const Decl *D) {
758761
if (isCurrentTRCContainedByDeploymentTarget())
759762
return false;
760763

test/Sema/availability_refinement_contexts.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,16 @@ func unavailableOnMacOS() {
319319
let x = 1
320320
}
321321

322+
// CHECK-NEXT: {{^}} (decl_implicit version=50 decl=extension.SomeEnum
323+
// CHECK-NEXT: {{^}} (decl version=51 decl=extension.SomeEnum
324+
// CHECK-NEXT: {{^}} (decl_implicit version=51 decl=unavailableOnMacOS
325+
// CHECK-NEXT: {{^}} (decl_implicit version=51 unavailable=macOS decl=unavailableOnMacOS
326+
@available(OSX 51, *)
327+
extension SomeEnum {
328+
@available(macOS, unavailable)
329+
var unavailableOnMacOS: Int { 1 }
330+
}
331+
322332
// CHECK-NEXT: {{^}} (decl_implicit version=50 decl=extension.SomeEnum
323333
// CHECK-NEXT: {{^}} (decl_implicit version=50 unavailable=macOS decl=extension.SomeEnum
324334
// CHECK-NEXT: {{^}} (decl_implicit version=50 unavailable=macOS decl=availableMacOS_52

0 commit comments

Comments
 (0)