Skip to content

Commit 5c61a2d

Browse files
committed
Sema: Require experimental feature to use custom availability domains.
1 parent 770ddad commit 5c61a2d

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6731,6 +6731,10 @@ WARNING(attr_availability_cannot_be_used_for_domain, none,
67316731
WARNING(attr_availability_expected_version_spec, none,
67326732
"expected 'introduced', 'deprecated', or 'obsoleted' in '%0' attribute "
67336733
"for platform '%1'", (StringRef, StringRef))
6734+
ERROR(attr_availability_requires_custom_availability, none,
6735+
"specifying '%0' in '%1' attribute requires "
6736+
"-enable-experimental-feature CustomAvailability",
6737+
(StringRef, const DeclAttribute))
67346738

67356739
ERROR(availability_decl_unavailable, none,
67366740
"%0 is unavailable%select{ in %2|}1%select{|: %3}3",

lib/Sema/TypeCheckAttr.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8386,6 +8386,15 @@ SemanticAvailableAttrRequest::evaluate(swift::Evaluator &evaluator,
83868386
return std::nullopt;
83878387
}
83888388

8389+
if (domain->isCustom() &&
8390+
!ctx.LangOpts.hasFeature(Feature::CustomAvailability) &&
8391+
!declContext->isInSwiftinterface()) {
8392+
diags.diagnose(domainLoc,
8393+
diag::attr_availability_requires_custom_availability,
8394+
*domainName, attr);
8395+
return std::nullopt;
8396+
}
8397+
83898398
mutableAttr->setCachedDomain(*domain);
83908399
}
83918400

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %target-typecheck-verify-swift \
2+
// RUN: -define-enabled-availability-domain SomeDomain
3+
4+
@available(SomeDomain, unavailable) // expected-error {{specifying 'SomeDomain' in '@available' attribute requires -enable-experimental-feature CustomAvailability}}
5+
func availableInSomeDomain() { }

0 commit comments

Comments
 (0)