Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-2290] Casting Bool to NSNumber that passed by generic parameter conforming ExpressibleByBooleanLiteral cause +[NSNumber initWithBooleanLiteral:]: unrecognized selector sent to class #44897

Closed
norio-nomura opened this issue Aug 6, 2016 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution

Comments

@norio-nomura
Copy link
Contributor

Previous ID SR-2290
Radar None
Original Reporter @norio-nomura
Type Bug
Status Closed
Resolution Done
Environment

Xcode 8 beta 4 (8S188o)

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

md5: a48db1cb1149b420c0ce248c68a938a7

Issue Description:

As workaround for SE-0109, I wrote code following:

import Foundation

func isTrue<T: ExpressibleByBooleanLiteral & Equatable>(_ v: T) -> Bool {
    return v == (true as T)
}

isTrue(1)

and got following error:

2016-08-06 18:44:54.771 com.apple.dt.Xcode.PlaygroundStub-macosx[96001:2430928] +[NSNumber initWithBooleanLiteral:]: unrecognized selector sent to class 0x7fff77fa8d80
2016-08-06 18:44:54.773 com.apple.dt.Xcode.PlaygroundStub-macosx[96001:2430928] An uncaught exception was raised
2016-08-06 18:44:54.773 com.apple.dt.Xcode.PlaygroundStub-macosx[96001:2430928] +[NSNumber initWithBooleanLiteral:]: unrecognized selector sent to class 0x7fff77fa8d80
2016-08-06 18:44:54.774 com.apple.dt.Xcode.PlaygroundStub-macosx[96001:2430928] (
    0   CoreFoundation                      0x00007fff85ebb4f2 __exceptionPreprocess + 178
    1   libobjc.A.dylib                     0x00007fff98610f7e objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff85f250ad +[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x00007fff85e2b571 ___forwarding___ + 1009
    4   CoreFoundation                      0x00007fff85e2b0f8 _CF_forwarding_prep_0 + 120
    5   libswiftFoundation.dylib            0x000000010b780781 _TTWCSo8NSNumbers27ExpressibleByBooleanLiteral10FoundationFS0_CfT14booleanLiteralwx18BooleanLiteralType_x + 49
    6   ???                                 0x000000010b93924e 0x0 + 4489187918
    7   ???                                 0x000000010b9390b1 0x0 + 4489187505
    8   com.apple.dt.Xcode.PlaygroundStub-macosx 0x00000001061fa380 main + 0
    9   CoreFoundation                      0x00007fff85e2ca6c __invoking___ + 140
    10  CoreFoundation                      0x00007fff85e2c8fe -[NSInvocation invoke] + 286
    11  CoreFoundation                      0x00007fff85e47d56 -[NSInvocation invokeWithTarget:] + 54
    12  ViewBridge                          0x00007fff98337e71 __68-[NSVB_ViewServiceImplicitAnimationDecodingProxy forwardInvocation:]_block_invoke + 47
    13  ViewBridge                          0x00007fff98342dfa __runAnimationGroup_block_invoke + 21
    14  AppKit                              0x00007fff94aa797f +[NSAnimationContext runAnimationGroup:completionHandler:] + 82
    15  ViewBridge                          0x00007fff98342dd6 runAnimationGroup + 331
    16  ViewBridge                          0x00007fff98337931 +[NSVB_View _animateWithAttributes:animations:completion:] + 531
    17  ViewBridge                          0x00007fff98337de2 -[NSVB_ViewServiceImplicitAnimationDecodingProxy forwardInvocation:] + 183
    18  CoreFoundation                      0x00007fff85e2b382 ___forwarding___ + 514
    19  CoreFoundation                      0x00007fff85e2b0f8 _CF_forwarding_prep_0 + 120
    20  CoreFoundation                      0x00007fff85e2ca6c __invoking___ + 140
    21  CoreFoundation                      0x00007fff85e2c8fe -[NSInvocation invoke] + 286
    22  CoreFoundation                      0x00007fff85e47d56 -[NSInvocation invokeWithTarget:] + 54
    23  ViewBridge                          0x00007fff983088c6 -[NSVB_QueueingProxy forwardInvocation:] + 323
    24  CoreFoundation                      0x00007fff85e2b382 ___forwarding___ + 514
    25  CoreFoundation                      0x00007fff85e2b0f8 _CF_forwarding_prep_0 + 120
    26  CoreFoundation                      0x00007fff85e2ca6c __invoking___ + 140
    27  CoreFoundation                      0x00007fff85e2c8fe -[NSInvocation invoke] + 286
    28  CoreFoundation                      0x00007fff85e47d56 -[NSInvocation invokeWithTarget:] + 54
    29  CoreFoundation                      0x00007fff85e2b382 ___forwarding___ + 514
    30  CoreFoundation                      0x00007fff85e2b0f8 _CF_forwarding_prep_0 + 120
    31  CoreFoundation                      0x00007fff85e2ca6c __invoking___ + 140
    32  CoreFoundation                      0x00007fff85e2c8fe -[NSInvocation invoke] + 286
    33  CoreFoundation                      0x00007fff85e47d56 -[NSInvocation invokeWithTarget:] + 54
    34  CoreFoundation                      0x00007fff85e2b382 ___forwarding___ + 514
    35  CoreFoundation                      0x00007fff85e2b0f8 _CF_forwarding_prep_0 + 120
    36  CoreFoundation                      0x00007fff85e2ca6c __invoking___ + 140
    37  CoreFoundation                      0x00007fff85e2c8fe -[NSInvocation invoke] + 286
    38  ViewBridge                          0x00007fff9834730b withHintInProgress + 501
    39  ViewBridge                          0x00007fff98347091 __deferNSXPCInvocationOntoMainThread_block_invoke_2 + 220
    40  ViewBridge                          0x00007fff982e5b4f +[NSViewServiceApplication withHostPID:invoke:] + 46
    41  ViewBridge                          0x00007fff98346f5f __deferNSXPCInvocationOntoMainThread_block_invoke + 129
    42  ViewBridge                          0x00007fff98346b6a __deferBlockOntoMainThread_block_invoke_2 + 448
    43  CoreFoundation                      0x00007fff85e504ac __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    44  CoreFoundation                      0x00007fff85e2fd05 __CFRunLoopDoBlocks + 341
    45  CoreFoundation                      0x00007fff85e2fa6b __CFRunLoopRun + 2347
    46  CoreFoundation                      0x00007fff85e2eed8 CFRunLoopRunSpecific + 296
    47  HIToolbox                           0x00007fff9c1f4935 RunCurrentEventLoopInMode + 235
    48  HIToolbox                           0x00007fff9c1f476f ReceiveNextEventCommon + 432
    49  HIToolbox                           0x00007fff9c1f45af _BlockUntilNextEventMatchingListInModeWithFilter + 71
    50  AppKit                              0x00007fff94a90df6 _DPSNextEvent + 1067
    51  AppKit                              0x00007fff94a90226 -[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 454
    52  ViewBridge                          0x00007fff982e6b21 -[NSViewServiceApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 73
    53  AppKit                              0x00007fff94a84d80 -[NSApplication run] + 682
    54  AppKit                              0x00007fff94a4e368 NSApplicationMain + 1176
    55  libxpc.dylib                        0x00007fff979b9194 _xpc_objc_main + 795
    56  libxpc.dylib                        0x00007fff979b7bbe xpc_main + 494
    57  ViewBridge                          0x00007fff9830c683 xpc_connection_handler + 0
    58  ViewBridge                          0x00007fff982ea9d9 NSViewServiceApplicationMain + 2818
    59  com.apple.dt.Xcode.PlaygroundStub-macosx 0x00000001061fa3a2 main + 34
    60  libdyld.dylib                       0x00007fff90c725ad start + 1
)

This issue also happen with `NSDecimalNumber`.
Following code is working as expected:

struct C: ExpressibleByBooleanLiteral, Equatable {
    var string: String
    init(_ string: String) {
        self.string = string
    }
    init(booleanLiteral value: Bool) {
        self.init(value ? "true" : "false")
    }
    static func ==(lhs: C, rhs: C) -> Bool {
        return lhs.string == rhs.string
    }
}

func isTrue<T: ExpressibleByBooleanLiteral & Equatable>(_ v: T) -> Bool {
    return v == (true as T)
}

isTrue(C("true")) // true
@belkadan
Copy link
Contributor

belkadan commented Aug 8, 2016

With implicit bridging of literals removed, the test case is now

import Foundation

func isTrue<T: ExpressibleByBooleanLiteral & Equatable>(_ v: T) -> Bool {
    return v == (true as T)
}

isTrue(1 as NSNumber)

but it's still occurring.

@Dante-Broggi
Copy link
Contributor

I think this is fixed by the Xcode 9.4.1 toolchain. If so, it should be closed.

@norio-nomura
Copy link
Contributor Author

I confirmed that this issue has been resolved on Xcode 9.4.1

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution
Projects
None yet
Development

No branches or pull requests

4 participants