Files
swift-mirror/test/Interpreter/convenience_init_swift5.swift
Slava Pestov 36e46c054d IRGen: Fix DynamicSelfType metadata recovery in @objc convenience initializers
An @objc convenience initializer can replace 'self'. Since IRGen
has no way to tell what the new 'self' value is from looking at
SIL, it always refers back to the original 'self' argument when
recovering DynamicSelfType metadata. This could cause a crash
if the metadata was used after the 'self' value had been
replaced.

To fix the crash, always insert the metadata recovery into the
entry block, where the 'self' value should be valid (even if
uninitialized, the 'isa' pointer should be correct).

Fixes <rdar://problem/50594689>.
2019-05-13 23:11:11 -04:00

37 lines
666 B
Swift

// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -o %t/main -swift-version 5
// RUN: %target-codesign %t/main
// RUN: %target-run %t/main
// REQUIRES: executable_test
// REQUIRES: objc_interop
import Foundation
import StdlibUnittest
func foo(_ x: @escaping () -> ()) { x() }
public class C {
var x: Int = 0
init(blah: ()) {}
@objc convenience init() {
self.init(blah: ())
foo { [weak self] in
guard let `self` = self else { return }
self.x += 1
}
}
}
var ConvenienceInitSelfTest = TestSuite("ConvenienceInitSelf")
ConvenienceInitSelfTest.test("SelfMetadata") {
let c = C()
expectEqual(c.x, 1)
}
runAllTests()