Swift 1.2: runtime exception when closed range includes max value for type

Originator:exsephiroth87
Number:rdar://19779978 Date Originated:10/02/2015
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 6.3 beta1 (6D520o) / Swift 1.2
Classification:Crash Reproducible:Alway
 
Summary:
When using a closed range in a switch case, and then end of the range is the maximum value for the variable type (e.g.: 0xFF for UInt8, 0xFFFF for UIn16, etc...), the application will crash at runtime when reaching the switch

Steps to Reproduce:
Sample code

let a: UInt8 = 0 // Any number here, doesn't matter
switch a {
case 0xF0...0xFF: // Any start value, doesn't matter
    println("a")
default:
    break
}

Expected Results:
Switch is executed correctly

Actual Results:
Console output:

fatal error: Range end index has no valid successor

Exception stack:

* thread #1: tid = 0x29ac1, 0x000000010589e0de libswiftCore.dylib`function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> () + 158, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
  * frame #0: 0x000000010589e0de libswiftCore.dylib`function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> () + 158
    frame #1: 0x0000000105dfc4d3 $__lldb_expr332`main + 1235 at playground332.swift:9
    frame #2: 0x0000000105673230 MyPlayground`_mh_execute_header + 25136
    frame #3: 0x00000001056757f1 MyPlayground`reabstraction thunk helper from @callee_owned () -> (@unowned ()) to @callee_owned (@in ()) -> (@out ()) + 17
    frame #4: 0x0000000105674a51 MyPlayground`partial apply forwarder for reabstraction thunk helper from @callee_owned () -> (@unowned ()) to @callee_owned (@in ()) -> (@out ()) + 81
    frame #5: 0x0000000105675870 MyPlayground`reabstraction thunk helper from @callee_owned (@in ()) -> (@out ()) to @callee_owned () -> (@unowned ()) + 32
    frame #6: 0x00000001056758a7 MyPlayground`reabstraction thunk helper from @callee_owned () -> (@unowned ()) to @callee_unowned @objc_block () -> (@unowned ()) + 39
    frame #7: 0x00007fff8d5992ac CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    frame #8: 0x00007fff8d58b3b5 CoreFoundation`__CFRunLoopDoBlocks + 341
    frame #9: 0x00007fff8d58ab6e CoreFoundation`__CFRunLoopRun + 910
    frame #10: 0x00007fff8d58a598 CoreFoundation`CFRunLoopRunSpecific + 296
    frame #11: 0x00007fff90b2cc4f HIToolbox`RunCurrentEventLoopInMode + 235
    frame #12: 0x00007fff90b2c8ce HIToolbox`ReceiveNextEventCommon + 179
    frame #13: 0x00007fff90b2c80b HIToolbox`_BlockUntilNextEventMatchingListInModeWithFilter + 71
    frame #14: 0x00007fff8c776a91 AppKit`_DPSNextEvent + 964
    frame #15: 0x00007fff8c776090 AppKit`-[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 194
    frame #16: 0x00007fff8c76bd93 AppKit`-[NSApplication run] + 594
    frame #17: 0x00000001056735a5 MyPlayground`main + 885
    frame #18: 0x00007fff8e5da5c9 libdyld.dylib`start + 1

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!