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
8 changes: 5 additions & 3 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -3826,7 +3826,8 @@ ERROR(decl_from_hidden_module,none,
"as result builder here|"
"in an extension with public or '@usableFromInline' members|"
"in an extension with conditional conformances|"
"in a public or '@usableFromInline' conformance}1; "
"in a public or '@usableFromInline' conformance|"
"in an '@available' attribute here}1; "
"%select{%2 has been imported as implementation-only|"
"it is an SPI imported from %2|"
"it is SPI|"
Expand All @@ -3841,7 +3842,8 @@ ERROR(typealias_desugars_to_type_from_hidden_module,none,
"as result builder here|"
"in an extension with public or '@usableFromInline' members|"
"in an extension with conditional conformance|"
"in a public or '@usableFromInline' conformance}3 "
"in a public or '@usableFromInline' conformance|"
"<<ERROR>>}3 "
"because %select{%4 has been imported as implementation-only|"
"it is an SPI imported from %4|"
"<<ERROR>>|"
Expand All @@ -3855,7 +3857,7 @@ ERROR(conformance_from_implementation_only_module,none,
"as result builder here|"
"in an extension with public or '@usableFromInline' members|"
"in an extension with conditional conformances|"
"<<ERROR>>}2; "
"<<ERROR>>|<<ERROR>>}2; "
"%select{%3 has been imported as implementation-only|"
"the conformance is declared as SPI in %3|"
"the conformance is declared as SPI|"
Expand Down
7 changes: 7 additions & 0 deletions lib/Sema/ResilienceDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
return true;
case ExportabilityReason::Inheritance:
return isa<ProtocolDecl>(D);
case ExportabilityReason::AvailableAttribute:
// If the context is an extension and that extension has an explicit
// access level, then access has already been diagnosed for the
// @available attribute.
if (auto *ED = dyn_cast_or_null<ExtensionDecl>(DC->getAsDecl()))
return !ED->getAttrs().getAttribute<AccessControlAttr>();
return false;
default:
return false;
}
Expand Down
16 changes: 3 additions & 13 deletions lib/Sema/TypeCheckAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2261,11 +2261,13 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {

void checkAvailabilityDomains(const Decl *D) {
D = D->getAbstractSyntaxDeclForAttributes();

auto where = Where.withReason(ExportabilityReason::AvailableAttribute);
for (auto attr : D->getSemanticAvailableAttrs()) {
if (auto *domainDecl = attr.getDomain().getDecl()) {
diagnoseDeclAvailability(domainDecl,
attr.getParsedAttr()->getDomainLoc(), nullptr,
Where, std::nullopt);
where, std::nullopt);
}
}
}
Expand Down Expand Up @@ -2557,18 +2559,6 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
: ExportabilityReason::ExtensionWithConditionalConformances;
checkConstrainedExtensionRequirements(ED, reason);

// Diagnose the exportability of the availability domains referenced by the
// @available attributes attached to the extension.
if (Where.isExported()) {
for (auto availableAttr : ED->getSemanticAvailableAttrs()) {
if (auto *domainDecl = availableAttr.getDomain().getDecl()) {
TypeChecker::diagnoseDeclRefExportability(
availableAttr.getParsedAttr()->getDomainLoc(), domainDecl,
Where.withReason(reason));
}
}
}

// If we haven't already visited the extended nominal visit it here.
// This logic is too wide but prevents false reports of an unused public
// import. We should instead check for public generic requirements
Expand Down
3 changes: 2 additions & 1 deletion lib/Sema/TypeCheckAvailability.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ enum class ExportabilityReason : unsigned {
ResultBuilder,
ExtensionWithPublicMembers,
ExtensionWithConditionalConformances,
Inheritance
Inheritance,
AvailableAttribute,
};

/// A description of the restrictions on what declarations can be referenced
Expand Down
Loading