Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -6989,6 +6989,17 @@ WARNING(attr_availability_expected_version_spec, none,
ERROR(attr_availability_requires_custom_availability, none,
"%0 requires '-enable-experimental-feature CustomAvailability'",
(AvailabilityDomain))
ERROR(attr_availability_domain_access, none,
"availability domain '%0' is "
"%select{private|fileprivate|internal|package|%error|%error}1 "
"and cannot be used in '%2' on "
"%select{private|fileprivate|internal|package|public|%error}3 %kind4",
(AvailabilityDomain, AccessLevel, DeclAttribute, AccessLevel,
const Decl *))
ERROR(attr_availability_domain_not_usable_from_inline, none,
"availability domain '%0' used in '%1' on %kind2 must be "
"'@usableFromInline' or public",
(AvailabilityDomain, DeclAttribute, const Decl *))

ERROR(availability_decl_unavailable, none,
"%0 is unavailable%select{ in %2|}1%select{|: %3}3",
Expand Down
4 changes: 1 addition & 3 deletions lib/AST/AvailabilityDomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ getCustomDomainKind(clang::FeatureAvailKind featureAvailKind) {
static const CustomAvailabilityDomain *
customDomainForClangDecl(ValueDecl *decl) {
auto *clangDecl = decl->getClangDecl();
ASSERT(clangDecl);

auto *varDecl = dyn_cast<clang::VarDecl>(clangDecl);
auto *varDecl = dyn_cast_or_null<clang::VarDecl>(clangDecl);
if (!varDecl)
return nullptr;

Expand Down
15 changes: 15 additions & 0 deletions lib/AST/DiagnosticEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//===----------------------------------------------------------------------===//

#include "swift/AST/DiagnosticEngine.h"
#include "swift/AST/AvailabilityDomain.h"
#include "swift/AST/ASTContext.h"
#include "swift/AST/ASTPrinter.h"
#include "swift/AST/Decl.h"
Expand Down Expand Up @@ -877,6 +878,20 @@ static void formatDiagnosticArgument(StringRef Modifier,
assert(Modifier.empty() && "Improper modifier for ValueDecl argument");
}

// Handle declarations representing an AvailabilityDomain specially.
if (auto VD = dyn_cast<ValueDecl>(D)) {
if (auto domain = AvailabilityDomain::forCustom(const_cast<ValueDecl *>(VD))) {
Out << "availability domain";

if (includeName) {
Out << " " << FormatOpts.OpeningQuotationMark;
Out << domain->getNameForDiagnostics();
Out << FormatOpts.ClosingQuotationMark;
}
break;
}
}

if (includeName) {
if (auto accessor = dyn_cast<AccessorDecl>(D)) {
// If it's an accessor, describe that and then switch to discussing its
Expand Down
6 changes: 6 additions & 0 deletions lib/Sema/MiscDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5257,6 +5257,12 @@ static bool diagnoseAvailabilityCondition(PoundAvailableInfo *info,
return true;
}

// Check the availability of the domain decl.
if (auto *domainDecl = spec.getDomain().getDecl()) {
auto where = ExportContext::forFunctionBody(DC, loc);
diagnoseDeclAvailability(domainDecl, loc, nullptr, where);
}

hasValidSpecs = true;
if (!domain.isPlatform())
allValidSpecsArePlatform = false;
Expand Down
Loading