Skip to content

[Runtime] Add entry for native swift objc reference to initWithTakeTa… #77569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stdlib/public/runtime/BytecodeLayouts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ constexpr InitFn initWithTakeTable[] = {
&copyingInitWithTake,
&copyingInitWithTake,
&copyingInitWithTake,
nullptr, // Custom
&copyingInitWithTake,
&metatypeInitWithTake,
nullptr, // Generic
&existentialInitWithTake,
Expand Down
48 changes: 48 additions & 0 deletions test/Interpreter/layout_string_witnesses_objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,51 @@ func testNestedGenericEnumSwiftObjC() {
}

testNestedGenericEnumSwiftObjC()

struct SwiftObjCAndWeakObjC {
let x: SwiftObjC
weak var y: NSObject?
}

func testSwiftObjCAndWeakObjC() {
let ptr = UnsafeMutablePointer<SwiftObjCAndWeakObjC>.allocate(capacity: 1)

// initWithCopy
do {
let x = SwiftObjCAndWeakObjC(x: SwiftObjC(), y: nil)
testInit(ptr, to: x)
}

// assignWithTake
do {
let y = SwiftObjCAndWeakObjC(x: SwiftObjC(), y: nil)

// CHECK-NEXT: Before deinit
print("Before deinit")

// CHECK-NEXT: SwiftObjC deinitialized!
testAssign(ptr, from: y)
}

// assignWithCopy
do {
var z = SwiftObjCAndWeakObjC(x: SwiftObjC(), y: nil)

// CHECK-NEXT: Before deinit
print("Before deinit")

// CHECK-NEXT: SwiftObjC deinitialized!
testAssignCopy(ptr, from: &z)
}

// CHECK-NEXT: Before deinit
print("Before deinit")

// destroy
// CHECK-NEXT: SwiftObjC deinitialized!
testDestroy(ptr)

ptr.deallocate()
}

testSwiftObjCAndWeakObjC()