Skip to content

[SR-4428] Error on accessing property on a object that was passed as a parameter in perform(_ aSelector: Selector!, with object: Any!) #47005

@swift-ci

Description

@swift-ci
Previous ID SR-4428
Radar None
Original Reporter alambov (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Apple Swift version 3.1 (swiftlang-802.0.48 clang-802.0.38)

Xcode
Version 8.3 (8E162)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Runtime
Assignee None
Priority Medium

md5: 9710840c1fa39ed7c7b70a916dff87f8

Issue Description:

Error occurs when an object that implements "Error" protocol is passed as "with" parameter in perform(_ aSelector: Selector![](, with object: Any)) method.

After that trying to access its "localizedDescription" property raises "object 0x608000012890 of class '__lldb_expr_56.PLError' does not implement methodSignatureForSelector"

Here is the test code:

import UIKit

struct PLError: Error {
    
}

class PLSender {
    
    
    init(withReceiver receiver: PLReceiver) {
        
        let error = PLError()
        
        print("Calling method direct:")
        
        receiver.testError(error: error)
        
        print("Calling method via perform selector:")
        
        receiver.perform(#selector(PLReceiver.testError(error:)), with: error)
    }
}

class PLReceiver: NSObject {
    
    func testError(error: Error) {
        print("Localized string is:", error.localizedDescription)
    }
    
}

let receiver = PLReceiver()

let sender = PLSender(withReceiver: receiver)

Here is console info:

Calling method direct:
Localized string is: The operation couldnt be completed. (__lldb_expr_74.PLError error 1.)
Calling method via perform selector:
2017-03-30 11:46:18.401 Test Error[1321:310854] -[_SwiftValue domain]: unrecognized selector sent to instance 0x610000028380
2017-03-30 11:46:18.403 Test Error[1321:310854] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_SwiftValue domain]: unrecognized selector sent to instance 0x610000028380'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000102151b0b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x0000000101bb6141 objc_exception_throw + 48
    2   CoreFoundation                      0x00000001021c1134 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   CoreFoundation                      0x00000001020d8840 ___forwarding___ + 1024
    4   CoreFoundation                      0x00000001020d83b8 _CF_forwarding_prep_0 + 120
    5   CoreFoundation                      0x0000000102100568 CFErrorGetDomain + 40
    6   libswiftFoundation.dylib            0x0000000110f1aa7e _TTWCSo7CFErrors5Error10FoundationFS0_g7_domainSS + 30
    7   libswiftCore.dylib                  0x00000001108ff2ee swift_stdlib_getErrorDomainNSString + 78
    8   libswiftCore.dylib                  0x0000000110adb68c _ZL28_swift_bridgeErrorToNSError_PN5swift10SwiftErrorE + 284
    9   libswiftFoundation.dylib            0x0000000110f19798 _TFE10FoundationPs5Errorg20localizedDescriptionSS + 184
    10  ???                                 0x00000001110f0c63 0x0 + 4581166179
    11  ???                                 0x00000001110f0d88 0x0 + 4581166472
    12  ???                                 0x00000001110f089b 0x0 + 4581165211
    13  ???                                 0x00000001110f09d0 0x0 + 4581165520
    14  ???                                 0x00000001110f01cf 0x0 + 4581163471
    15  Test Error                          0x00000001015e5610 main + 0
    16  CoreFoundation                      0x00000001020f7b5c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    17  CoreFoundation                      0x00000001020dce54 __CFRunLoopDoBlocks + 356
    18  CoreFoundation                      0x00000001020dc5ee __CFRunLoopRun + 894
    19  CoreFoundation                      0x00000001020dc016 CFRunLoopRunSpecific + 406
    20  GraphicsServices                    0x000000010750aa24 GSEventRunModal + 62
    21  UIKit                               0x0000000102c5e0d4 UIApplicationMain + 159
    22  Test Error                          0x00000001015e56d9 main + 201
    23  libdyld.dylib                       0x000000010569865d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Please find attached Swift playground that demonstrates this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfruntimeThe Swift Runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions