Files
swift-mirror/test/Interpreter/lifetime_nonmutating_address_only.swift
Erik Eckstein 66e801b0e8 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.
2025-01-27 10:38:30 +01:00

33 lines
569 B
Swift

// RUN: %target-run-simple-swift | %FileCheck %s
// REQUIRES: executable_test
// https://github.com/apple/swift/issues/51493
// CHECK: A
// CHECK: B
// CHECK: C
protocol SomeProtocol { }
class SomeClass: SomeProtocol { deinit { print("C") } }
struct SomeStruct { var x, y: Int }
extension SomeProtocol {
var someProperty: SomeStruct {
nonmutating set {
print("B")
}
get {
print("A")
return SomeStruct(x: 1, y: 2)
}
}
}
func testit() {
let c = SomeClass()
c.someProperty.x = 32
}
testit()