Files
swift-mirror/test/Interpreter/rdar108705703.swift
Dario Rexin 6d031cbada [IRGen] Respect optionality of unowned(unsafe) reference properties (#65663)
* [IRGen] Respect optionality of unowned(unsafe) reference properties

rdar://108705703

When generating the type info for fields marked unowned(unsafe) of an optional reference (e.g. AnyObject?), we dropped the fact that it was optional along the way. This caused incorrect tags to be returned when on object of the type was stored in an optional itself and the unowned property contained `nil`. In those cases the outer optional appeared to be `nil` as well, even if it in fact contained a value.

* Fix additional case
2023-05-05 09:37:46 -07:00

29 lines
468 B
Swift

// RUN: %target-run-simple-swift | %FileCheck %s
// REQUIRES: executable_test
struct Context {
unowned(unsafe) var x: AnyObject? = nil
}
@inline(never)
func test(x: Context) -> Context? {
return x
}
// CHECK: works
if (test(x: Context()) == nil) {
print("bug")
} else {
print("works")
}
@inline(never)
func test2() -> Context {
var g: [Context] = [Context()]
print(g.endIndex)
return g.removeLast()
}
// CHECK: Context(x: nil)
print(test2())