-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Open
Labels
access controlFeature → modifiers: Access control and access levelsFeature → modifiers: Access control and access levelsbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfregressionswift 4.2
Description
Previous ID | SR-8516 |
Radar | rdar://problem/43142446 |
Original Reporter | @zienag |
Type | Bug |
Environment
Xcode Version 10.0 beta 5 (10L221o)
Additional Detail from JIRA
Votes | 2 |
Component/s | Compiler |
Labels | Bug, 4.2Regression |
Assignee | None |
Priority | Medium |
md5: ddbc0a221a0bcf1304753842fa034776
is duplicated by:
- SR-8534 Crash with NSNumber.init + TimeInterval
Issue Description:
Encountered bug with unrecognised selector exception. After digging it down, it appeared that there was NSConcreteValue in swift array of NSNumbers.
Code to reproduce:
_ = [0, 0.2].map(NSNumber.init).map { $0.doubleValue }
It throws:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteValue doubleValue]: unrecognized selector sent to instance 0x102a5e320'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff2b8d82db __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00007fff52a82c76 objc_exception_throw + 48
2 CoreFoundation 0x00007fff2b970db4 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x00007fff2b84e820 ___forwarding___ + 1456
4 CoreFoundation 0x00007fff2b84e1e8 _CF_forwarding_prep_0 + 120
5 test 0x0000000100002030 $S4testSdSo8NSNumberCXEfU_ + 32
6 test 0x000000010000205d $SSo8NSNumberCSds5Error_pIggdzo_ABSdsAC_pIegnrzo_TR + 29
7 test 0x00000001000020fb $SSo8NSNumberCSds5Error_pIggdzo_ABSdsAC_pIegnrzo_TRTA + 27
8 test 0x0000000100079b0f $SSlsE3mapySayqd__Gqd__7ElementQzKXEKlF + 527
9 test 0x00000001000018e1 main + 641
10 libdyld.dylib 0x00007fff5369c015 start + 1
11 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Workarounds:
// put .0 to indicate that it is a double literal.
_ = [0.0, 0.2].map(NSNumber.init).map { $0.doubleValue }
// using closure and call initializer inside
_ = [0, 0.2].map { NSNumber(value: $0) }.map { $0.doubleValue }
// explicitly marking type of a function
_ = [0, 0.2].map(NSNumber.init as (Double) -> NSNumber).map { $0.doubleValue }
// extracting array to let constant
let array = [0, 0.2]
_ = array.map(NSNumber.init).map { $0.doubleValue }
Metadata
Metadata
Assignees
Labels
access controlFeature → modifiers: Access control and access levelsFeature → modifiers: Access control and access levelsbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfregressionswift 4.2