Skip to content

Commit 9da14a2

Browse files
authored
---
yaml --- r: 344507 b: refs/heads/swift-5.1-branch-08-28-2019 c: e1ac27c h: refs/heads/master i: 344505: c3806fa 344503: 118f34a
1 parent e0fbf66 commit 9da14a2

File tree

7 files changed

+76
-3
lines changed

7 files changed

+76
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1508,4 +1508,4 @@ refs/heads/revert-27301-syntaxparse-associatedtype: 859f90afc1557bf5600de108927b
15081508
refs/heads/shahmishal/pr-test-swift: 868c7a884713b910757f2f3d4c413e395aeba76c
15091509
refs/heads/shahmishal/pr-test-swift-2: fa33242bb6401b5206e2e3ce50624febfc469625
15101510
refs/heads/swift-5.1-branch-07-24-2019: 0450b7d81e75701c325138e6af52d470bb3dafdd
1511-
refs/heads/swift-5.1-branch-08-28-2019: ed27f9f9cec5831968b29451078e5929ad1bd415
1511+
refs/heads/swift-5.1-branch-08-28-2019: e1ac27c5c180bf6817cca3d43d429a8717a45eb7

branches/swift-5.1-branch-08-28-2019/lib/AST/ASTContext.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4382,6 +4382,14 @@ OpaqueTypeArchetypeType::get(OpaqueTypeDecl *Decl,
43824382
auto opaqueInterfaceTy = Decl->getUnderlyingInterfaceType();
43834383
auto layout = signature->getLayoutConstraint(opaqueInterfaceTy);
43844384
auto superclass = signature->getSuperclassBound(opaqueInterfaceTy);
4385+
#if !DO_IT_CORRECTLY
4386+
// Ad-hoc substitute the generic parameters of the superclass.
4387+
// If we correctly applied the substitutions to the generic signature
4388+
// constraints above, this would be unnecessary.
4389+
if (superclass && superclass->hasTypeParameter()) {
4390+
superclass = superclass.subst(Substitutions);
4391+
}
4392+
#endif
43854393
SmallVector<ProtocolDecl*, 4> protos;
43864394
for (auto proto : signature->getConformsTo(opaqueInterfaceTy)) {
43874395
protos.push_back(proto);

branches/swift-5.1-branch-08-28-2019/lib/AST/Attr.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,8 +1073,15 @@ const AvailableAttr *AvailableAttr::isUnavailable(const Decl *D) {
10731073
return attr;
10741074

10751075
// If D is an extension member, check if the extension is unavailable.
1076-
if (auto ext = dyn_cast<ExtensionDecl>(D->getDeclContext()))
1077-
return AvailableAttr::isUnavailable(ext);
1076+
//
1077+
// Skip decls imported from Clang, they could be associated to the wrong
1078+
// extension and inherit undesired unavailability. The ClangImporter
1079+
// associates Objective-C protocol members to the first category where the
1080+
// protocol is directly or indirectly adopted, no matter its availability
1081+
// and the availability of other categories. rdar://problem/53956555
1082+
if (!D->getClangNode())
1083+
if (auto ext = dyn_cast<ExtensionDecl>(D->getDeclContext()))
1084+
return AvailableAttr::isUnavailable(ext);
10781085

10791086
return nullptr;
10801087
}

branches/swift-5.1-branch-08-28-2019/lib/Sema/TypeCheckGeneric.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ Type TypeChecker::getOrCreateOpaqueResultType(TypeResolution resolution,
231231
diag::opaque_type_invalid_constraint);
232232
return constraintTypeLoc.getType();
233233
}
234+
235+
if (constraintType->hasArchetype())
236+
constraintType = constraintType->mapTypeOutOfContext();
234237

235238
// Create a generic signature for the opaque environment. This is the outer
236239
// generic signature with an added generic parameter representing the opaque
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#import <Foundation/Foundation.h>
2+
3+
@interface SharedInterface
4+
@end
5+
6+
@protocol SharedProtocol <NSObject>
7+
+ (NSInteger)foo;
8+
@end
9+
10+
// ClangImporter imports the first category as the extension parent of
11+
// SharedInterface.foo, making foo unavailable on macOS when the extension
12+
// unavailability is inherited by its members.
13+
API_UNAVAILABLE(macos)
14+
@interface SharedInterface (IOSCategory) <SharedProtocol>
15+
@end
16+
17+
API_UNAVAILABLE(ios)
18+
@interface SharedInterface (MacOSCategory) <SharedProtocol>
19+
@end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %target-swift-frontend -typecheck %s -import-objc-header %S/Inputs/availability_platform_categories.h
2+
3+
// REQUIRES: OS=macos
4+
5+
// Test when a function is associated to an Objective-C category with the
6+
// wrong unavailability. rdar://problem/53956555
7+
8+
print(SharedInterface.foo())
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %target-swift-frontend -disable-availability-checking -emit-ir -verify %s
2+
3+
// rdar://problem/53318811
4+
5+
class Foo<T> {
6+
var x: T { fatalError() }
7+
}
8+
9+
func foo<T>(_: T) -> some Foo<T> {
10+
let localProp: some Foo<T> = Foo()
11+
return localProp
12+
}
13+
14+
class C<T> {
15+
func bar() -> some Foo<T> {
16+
return Foo()
17+
}
18+
19+
var prop: some Foo<T> = Foo()
20+
}
21+
22+
func bar() -> Int {
23+
var x = 0
24+
x = foo(0).x
25+
x = C<Int>().bar().x
26+
x = C<Int>().prop.x
27+
return x
28+
}

0 commit comments

Comments
 (0)