Skip to content

Commit 3c1a6ab

Browse files
committed
Reject member lookups that require bridging metatypes
We can only coerce metatypes covariantly but bridging always requires an unrelated metatype cast. When performing member lookup, especially unqualified member lookup, disregard static members from bridged types entirely. See SR-5670 and rdar://problem/33830526
1 parent 037ab30 commit 3c1a6ab

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3263,7 +3263,7 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
32633263

32643264
// If the instance type is a bridged to an Objective-C type, perform
32653265
// a lookup into that Objective-C type.
3266-
if (bridgedType) {
3266+
if (bridgedType && !isMetatype) {
32673267
LookupResult &bridgedLookup = lookupMember(bridgedClass, memberName);
32683268
ModuleDecl *foundationModule = nullptr;
32693269
for (auto result : bridgedLookup) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@import Foundation;
2+
3+
// rdar://problem/33830526: Constraint system should not add static methods
4+
// to the overload search space if it would require bridging unrelated metatypes.
5+
@interface NSString (Extension)
6+
+ (void) meth;
7+
@end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-swift-frontend -typecheck -import-objc-header %S/Inputs/invalid_metatype_bridging_header.h %s -verify
2+
3+
// REQUIRES: objc_interop
4+
5+
// rdar://problem/33830526: Constraint system should not add static methods
6+
// to the overload search space if it would require bridging unrelated metatypes.
7+
class Crasher {
8+
static func called(argument: String) {}
9+
}
10+
11+
Crasher.called(argument: .meth) // expected-error {{type 'String' has no member 'meth'}}
12+
Crasher.called(argument: String.meth) // expected-error {{type 'String' has no member 'meth'}}

0 commit comments

Comments
 (0)