Skip to content

Commit a42c5bd

Browse files
authored
Merge pull request #71629 from apple/objcimpl-function-crash
Fix crash checking objcImpl block property
2 parents 4e51846 + 6438b96 commit a42c5bd

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

lib/Sema/TypeCheckDeclObjC.cpp

+15-7
Original file line numberDiff line numberDiff line change
@@ -3283,17 +3283,25 @@ class ObjCImplementationChecker {
32833283
if (reqParams.size() != implParams.size())
32843284
return false;
32853285

3286-
auto implParamList =
3287-
cast<AbstractFunctionDecl>(implDecl)->getParameters();
3286+
ParameterList *implParamList = nullptr;
3287+
if (auto afd = dyn_cast<AbstractFunctionDecl>(implDecl))
3288+
implParamList = afd->getParameters();
32883289

32893290
for (auto i : indices(reqParams)) {
32903291
const auto &reqParam = reqParams[i];
32913292
const auto &implParam = implParams[i];
3292-
ParamDecl *implParamDecl = implParamList->get(i);
3293-
3294-
if (!matchParamTypes(reqParam.getOldType(), implParam.getOldType(),
3295-
implParamDecl))
3296-
return false;
3293+
if (implParamList) {
3294+
// Some of the parameters may be IUOs; apply special logic.
3295+
if (!matchParamTypes(reqParam.getOldType(),
3296+
implParam.getOldType(),
3297+
implParamList->get(i)))
3298+
return false;
3299+
} else {
3300+
// IUOs not allowed here; apply ordinary logic.
3301+
if (!reqParam.getOldType()->matchesParameter(
3302+
implParam.getOldType(), matchOpts))
3303+
return false;
3304+
}
32973305
}
32983306

32993307
return matchTypes(funcReqTy->getResult(), funcImplTy->getResult(),

test/decl/ext/Inputs/objc_implementation.h

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
- (void)instanceMethod1:(int)param;
5858
- (void)instanceMethod2:(int)param;
5959

60+
// rdar://122280735 - crash when the parameter of a block property needs @escaping
61+
@property (nonatomic, readonly) void (^ _Nonnull rdar122280735)(void (^_Nonnull completion)());
62+
6063
@end
6164

6265
@interface ObjCClass () <NSCopying>

test/decl/ext/objc_implementation.swift

+4
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ protocol EmptySwiftProto {}
225225
// OK
226226
return self
227227
}
228+
229+
// rdar://122280735 - crash when the parameter of a block property needs @escaping
230+
let rdar122280735: (() -> ()) -> Void = { _ in }
231+
// expected-warning@-1 {{property 'rdar122280735' of type '(() -> ()) -> Void' does not match type '(@escaping () -> Void) -> Void' declared by the header}}
228232
}
229233

230234
@_objcImplementation(PresentAdditions) extension ObjCClass {

test/decl/ext/objc_implementation_conflicts.swift

+2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ import objc_implementation_private
175175
@objc func extensionMethod(fromHeader2: CInt) {}
176176

177177
@objc(copyWithZone:) func copy(with zone: NSZone?) -> Any { self }
178+
179+
let rdar122280735: (@escaping () -> ()) -> Void = { _ in }
178180
}
179181

180182
@_objcImplementation(PresentAdditions) extension ObjCClass {

0 commit comments

Comments
 (0)