Last active
October 14, 2016 20:07
Swift 3.0 optimizations crash (fixed in Xcode 8.1 beta 3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// | |
/// This code crashes with Swift 3.0 with optimizations enabled | |
/// Run with: | |
/// $ swift -O optimizationCrash.swift | |
/// | |
extension Dictionary { | |
// init(pairs: [(Key, Value)]?) { // With `(Key, Value)` this doesn't crash | |
init(pairs: [Element]?) { // With `Element` this crashes with -0 | |
self.init() | |
} | |
} | |
let elements: [(Int, Int)] = [(1, 1)] | |
dump(Dictionary(pairs: elements)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Dictionary { | |
init(_ pairs: [(Key, Value)]?) { | |
self.init() | |
for (k, v) in pairs ?? [] { | |
self[k] = v | |
} | |
} | |
} | |
let dictionary: [String: Int] = ["hi": 1] | |
let array: [(String, Int)] = dictionary.filter { _ in return true } // Crashes using filter | |
// var array = [(String, Int)]() // Doesn't crash if you use a for loop | |
// for (key, value) in dictionary { | |
// array.append((key, value)) | |
// } | |
dump(Dictionary(array)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment