Skip to content

Commit 9b59ec5

Browse files
committed
Allow the use of unavailable types from unavailable code
This change permits the use of unavailable types in unavailable signatures. It affects only usage of `available(*, unavailable)`. This fixes a compilation error in swift-corelibs-foundation/Foundation/ URLSession/URLSessionConfiguration.swift where an unavailable property was typed by an unavailable type.
1 parent 67798cd commit 9b59ec5

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,13 +1503,17 @@ static bool isInsideUnavailableDeclaration(SourceRange ReferenceRange,
15031503
/// Returns true if the reference or any of its parents is an
15041504
/// unconditional unavailable declaration for the same platform.
15051505
static bool isInsideCompatibleUnavailableDeclaration(
1506-
SourceRange ReferenceRange, const DeclContext *ReferenceDC,
1507-
const AvailableAttr *attr) {
1506+
const ValueDecl *referencedD, SourceRange ReferenceRange,
1507+
const DeclContext *ReferenceDC, const AvailableAttr *attr) {
15081508
if (!attr->isUnconditionallyUnavailable()) {
15091509
return false;
15101510
}
1511+
1512+
// Refuse calling unavailable functions from unavailable code,
1513+
// but allow the use of types.
15111514
PlatformKind platform = attr->Platform;
1512-
if (platform == PlatformKind::none) {
1515+
if (platform == PlatformKind::none &&
1516+
!isa<TypeDecl>(referencedD)) {
15131517
return false;
15141518
}
15151519

@@ -2129,7 +2133,7 @@ bool swift::diagnoseExplicitUnavailability(
21292133
// unavailability is OK -- the eventual caller can't call the
21302134
// enclosing code in the same situations it wouldn't be able to
21312135
// call this code.
2132-
if (isInsideCompatibleUnavailableDeclaration(R, DC, Attr)) {
2136+
if (isInsideCompatibleUnavailableDeclaration(D, R, DC, Attr)) {
21332137
return false;
21342138
}
21352139

test/attr/attr_availability.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,3 +1069,16 @@ func rdar46348825_deprecated() {}
10691069
@available(swift, obsoleted: 4.0, obsoleted: 4.0)
10701070
// expected-warning@-1 {{'obsoleted' argument has already been specified}}
10711071
func rdar46348825_obsoleted() {}
1072+
1073+
// Referencing unavailable types in signatures of unavailable functions should be accepted
1074+
@available(*, unavailable)
1075+
protocol UnavailableProto {
1076+
}
1077+
1078+
@available(*, unavailable)
1079+
func unavailableFunc(_ arg: UnavailableProto) -> UnavailableProto {}
1080+
1081+
@available(*, unavailable)
1082+
struct S {
1083+
var a: UnavailableProto
1084+
}

0 commit comments

Comments
 (0)