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
4 changes: 4 additions & 0 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -7282,6 +7282,10 @@ ERROR(conformance_availability_only_version_newer, none,
"conformance of %0 to %1 is only available in %2 %3 or newer",
(Type, Type, AvailabilityDomain, AvailabilityRange))

ERROR(conformance_availability_not_available, none,
"conformance of %0 to %1 is only available in %2",
(Type, Type, AvailabilityDomain))

//------------------------------------------------------------------------------
// MARK: if #available(...)
//------------------------------------------------------------------------------
Expand Down
15 changes: 15 additions & 0 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,21 @@ static void configureAvailabilityDomains(const ASTContext &ctx,
for (auto dynamic : opts.AvailabilityDomains.DynamicDomains)
createAndInsertDomain(dynamic, CustomAvailabilityDomain::Kind::Dynamic);

// If we didn't see the UnicodeNormalization availability domain, set it
// appropriately.
if (domainMap.count(ctx.getIdentifier("UnicodeNormalization")) == 0) {
if (ctx.LangOpts.hasFeature(Feature::Embedded)) {
// Embedded Swift disables this domain by default.
createAndInsertDomain("UnicodeNormalization",
CustomAvailabilityDomain::Kind::Enabled);
} else {
// Non-Embedded Swift always enables the Unicode tables.
createAndInsertDomain("UnicodeNormalization",
CustomAvailabilityDomain::Kind::AlwaysEnabled);
}
}


mainModule->setAvailabilityDomains(std::move(domainMap));
}

Expand Down
2 changes: 0 additions & 2 deletions lib/SILGen/SILGenDestructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ void SILGenFunction::emitDistributedRemoteActorDeinit(

auto cleanupLoc = CleanupLocation(loc);

auto &C = cd->getASTContext();

{
FullExpr CleanupScope(Cleanups, cleanupLoc);
ManagedValue borrowedSelf = emitManagedBeginBorrow(loc, selfValue);
Expand Down
17 changes: 12 additions & 5 deletions lib/Sema/TypeCheckAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,15 +1041,22 @@ static bool diagnosePotentialUnavailability(
{
auto type = rootConf->getType();
auto proto = rootConf->getProtocol()->getDeclaredInterfaceType();
auto err = ctx.Diags.diagnose(
loc, diag::conformance_availability_only_version_newer, type, proto,
domain, availability);
auto err = availability.hasMinimumVersion()
? ctx.Diags.diagnose(
loc, diag::conformance_availability_only_version_newer, type, proto,
domain, availability)
: ctx.Diags.diagnose(
loc, diag::conformance_availability_not_available, type, proto,
domain);

auto behaviorLimit = behaviorLimitForExplicitUnavailability(rootConf, dc);
if (behaviorLimit >= DiagnosticBehavior::Warning)
if (!availability.hasMinimumVersion()) {
// Don't downgrade
} else if (behaviorLimit >= DiagnosticBehavior::Warning) {
err.limitBehavior(behaviorLimit);
else
} else {
err.warnUntilSwiftVersion(6);
}

// Direct a fixit to the error if an existing guard is nearly-correct
if (fixAvailabilityByNarrowingNearbyVersionCheck(loc, dc, domain,
Expand Down
28 changes: 28 additions & 0 deletions test/Availability/availability_custom_domains.swift
Original file line number Diff line number Diff line change
Expand Up @@ -568,3 +568,31 @@ class DerivedUnavailable2: BaseAvailableInEnabledDomain { } // expected-error {{
@available(DisabledDomain, unavailable)
class DerivedUnavailable3: BaseAvailableInEnabledDomain { }


// Protocol conformance availability.
protocol P { }

struct MyType1 { }

@available(EnabledDomain)
extension MyType1: P { }

struct MyType2 { }

@available(AlwaysEnabledDomain)
extension MyType2: P { }

struct MyType3 { }

@available(DisabledDomain)
extension MyType3: P { }

func acceptP<T: P>(_: T.Type) { }

func testP() { // expected-note 2{{add '@available' attribute to enclosing global function}}
acceptP(MyType1.self) // expected-error{{conformance of 'MyType1' to 'P' is only available in EnabledDomain}}
// expected-note@-1{{add 'if #available' version check}}
acceptP(MyType2.self) // okay
acceptP(MyType3.self) // expected-error{{conformance of 'MyType3' to 'P' is only available in DisabledDomain}}
// expected-note@-1{{add 'if #available' version check}}
}