Skip to content

Commit 66e801b

Browse files
committed
tests: fix lifetimes of objects in two tests
Those tests rely on lexical object lifetimes. But lifetimes are only guaranteed for "variables" but not for temporary objects. Storing those objects in variables fixes the issue. This fixes the tests when running them in optimize mode and when OSSA modules are enabled. This is part of rdar://140229560.
1 parent 70a0564 commit 66e801b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

test/Interpreter/lifetime_nonmutating_address_only.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,10 @@ extension SomeProtocol {
2323
}
2424
}
2525

26-
SomeClass().someProperty.x = 32
26+
func testit() {
27+
let c = SomeClass()
28+
c.someProperty.x = 32
29+
}
30+
31+
testit()
32+

validation-test/stdlib/ErrorHandling.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,10 @@ ErrorHandlingTests.test("ErrorHandling/Sequence filter") {
303303
let initialCount = NoisyCount
304304
for condition in [true, false] {
305305
for throwAtCount in 0...3 {
306-
let sequence = [Noisy(), Noisy(), Noisy()]
306+
let n1 = Noisy()
307+
let n2 = Noisy()
308+
let n3 = Noisy()
309+
let sequence = [n1, n2, n3]
307310
var loopCount = 0
308311
do {
309312
let result: [Noisy] = try sequence.filter { _ in

0 commit comments

Comments
 (0)