mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
We were creating the JumpDests too early, so lowering a 'break' or 'continue' statement would perform cleanups that were recorded while evaluating the pack expansion expression, which would cause SIL verifier errors and runtime crashes. - Fixes https://github.com/swiftlang/swift/issues/78598 - Fixes rdar://131847933
47 lines
946 B
Swift
47 lines
946 B
Swift
// RUN: %target-run-simple-swift
|
|
|
|
// REQUIRES: executable_test
|
|
|
|
import StdlibUnittest
|
|
|
|
var packIter = TestSuite("PackIteration")
|
|
|
|
packIter.test("break") {
|
|
func breakTest<each T: Hashable>(_ ts: (repeat (each T)?)) -> [AnyHashable] {
|
|
var result: [AnyHashable] = []
|
|
|
|
for t in repeat each ts {
|
|
if let t {
|
|
result.append(t)
|
|
} else {
|
|
break
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
let results = breakTest((0, "hello", nil as Bool?, 3.14))
|
|
expectEqual(results, [0, "hello"] as [AnyHashable])
|
|
}
|
|
|
|
packIter.test("break") {
|
|
func continueTest<each T: Hashable>(_ ts: (repeat (each T)?)) -> [AnyHashable] {
|
|
var result: [AnyHashable] = []
|
|
|
|
for t in repeat each ts {
|
|
if let t {
|
|
result.append(t)
|
|
} else {
|
|
continue
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
let results = continueTest((0, "hello", nil as Bool?, 3.14))
|
|
expectEqual(results, [0, "hello", 3.14] as [AnyHashable])
|
|
}
|
|
|
|
runAllTests() |