UI_USER_INTERFACE_IDIOM() causes a crash in static Swift constant when optimization is enabled

Originator:serieuxchat
Number:rdar://21175489 Date Originated:May 31, 2015
Status:Closed Resolved:
Product:iOS Product Version:
Classification: Reproducible:
 
This issue was fixed in Xcode 7 beta 2

=========================================
Summary:
The function UI_USER_INTERFACE_IDIOM(), when called to determine the value of a static constant (in a Swift class), causes the app to crash. This happens only when compiler optimization is enabled.

Steps to Reproduce:
- Open the attached sample project file.
- Build and run the app (make sure that Release configuration is selected, where optimization is enabled).



Expected Results:
- The size declared in the ImageFormatSize class must be printed on the Console.

Actual Results:
The app crashes with the following Console output:

2015-05-31 11:58:32.567 SwiftCrash[2826:435294] *** NSForwarding: warning: selector (0x107a284fd) for message 'currentDevice' does not match selector known to Objective C runtime (0x10c883c36)-- abort
2015-05-31 11:58:32.567 SwiftCrash[2826:435294] +[UIDevice currentDevice]: unrecognized selector sent to class 0x109290248
2015-05-31 11:58:32.574 SwiftCrash[2826:435294] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[UIDevice currentDevice]: unrecognized selector sent to class 0x109290248'
*** First throw call stack:
(
	0   CoreFoundation                      0x0000000107c19c65 __exceptionPreprocess + 165
	1   libobjc.A.dylib                     0x0000000109784bb7 objc_exception_throw + 45
	2   CoreFoundation                      0x0000000107c20fad +[NSObject(NSObject) doesNotRecognizeSelector:] + 205
	3   CoreFoundation                      0x0000000107b7713c ___forwarding___ + 988
	4   CoreFoundation                      0x0000000107b76cd8 _CF_forwarding_prep_0 + 120
	5   SwiftCrash                          0x0000000107a244f0 globalinit_33_454CCB527129803F40839F353AC41F64_func0 + 32
	6   libswiftCore.dylib                  0x0000000109af6bf0 __swift_once_block_invoke + 16
	7   libdispatch.dylib                   0x0000000109ea8614 _dispatch_client_callout + 8
	8   libdispatch.dylib                   0x0000000109e94881 dispatch_once_f + 565
	9   libswiftCore.dylib                  0x0000000109af6bcd swift_once + 157
	10  SwiftCrash                          0x0000000107a24114 _TToFC10SwiftCrash11AppDelegate11applicationfS0_FTCSo13UIApplication29didFinishLaunchingWithOptionsGSqGVSs10DictionaryCSo8NSObjectPSs9AnyObject____Sb + 196
	11  UIKit                               0x00000001084b3788 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 240
	12  UIKit                               0x00000001084b4397 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2540
	13  UIKit                               0x00000001084b71de -[UIApplication _runWithMainScene:transitionContext:completion:] + 1349
	14  UIKit                               0x00000001084b60d5 -[UIApplication workspaceDidEndTransaction:] + 179
	15  FrontBoardServices                  0x000000010b2945e5 __31-[FBSSerialQueue performAsync:]_block_invoke_2 + 21
	16  CoreFoundation                      0x0000000107b4d41c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
	17  CoreFoundation                      0x0000000107b43165 __CFRunLoopDoBlocks + 341
	18  CoreFoundation                      0x0000000107b42f25 __CFRunLoopRun + 2389
	19  CoreFoundation                      0x0000000107b42366 CFRunLoopRunSpecific + 470
	20  UIKit                               0x00000001084b5b42 -[UIApplication 

Version:
This happens with both Xcode 6.3.2 and 6.4 beta

Notes:


Configuration:
This happens with both Xcode 6.3.2 and 6.4 beta

Update: Also in Xcode 7 beta

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!