Files
swift-mirror/test/Interpreter/pack_iteration.swift
Slava Pestov 522a6b7c80 SILGen: Fix break/continue inside 'for ... in ... repeat' loop
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
2025-11-10 20:51:45 -05:00

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()