Skip to content

Commit e65014e

Browse files
Suyash SrijanSuyash Srijan
authored andcommitted
[typechecker] allow @objc functions to return dynamic self
1 parent c86351d commit e65014e

File tree

3 files changed

+2
-3
lines changed

3 files changed

+2
-3
lines changed

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ bool swift::isRepresentableInObjC(
523523
if (!ResultType->hasError() &&
524524
!ResultType->isVoid() &&
525525
!ResultType->isUninhabited() &&
526+
!ResultType->hasDynamicSelfType() &&
526527
!ResultType->isRepresentableIn(ForeignLanguage::ObjectiveC,
527528
const_cast<FuncDecl *>(FD))) {
528529
if (Diagnose) {

test/ClangImporter/objc_parse.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,7 @@ func classAnyObject(_ obj: NSObject) {
273273
class Wobbler : NSWobbling {
274274
@objc func wobble() { }
275275

276-
func returnMyself() -> Self { return self } // expected-error{{non-'@objc' method 'returnMyself()' does not satisfy requirement of '@objc' protocol 'NSWobbling'}}{{none}}
277-
// expected-error@-1{{method cannot be an implementation of an @objc requirement because its result type cannot be represented in Objective-C}}
276+
func returnMyself() -> Self { return self }
278277
}
279278

280279
extension Wobbler : NSMaybeInitWobble { // expected-error{{type 'Wobbler' does not conform to protocol 'NSMaybeInitWobble'}}

test/attr/attr_objc.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ class ConcreteContext3 {
323323
func dynamicSelf1() -> Self { return self }
324324

325325
@objc func dynamicSelf1_() -> Self { return self }
326-
// expected-error@-1{{method cannot be marked @objc because its result type cannot be represented in Objective-C}}
327326

328327
@objc func genericParams<T: NSObject>() -> [T] { return [] }
329328
// expected-error@-1{{method cannot be marked @objc because it has generic parameters}}

0 commit comments

Comments
 (0)