phase: 20.49 COMPLETE; 20.50 Flow+String minimal reps; 20.51 selfhost v0/v1 minimal (Option A/B); hv1-inline binop/unop/copy; docs + run_all + CURRENT_TASK -> 21.0
This commit is contained in:
62
local_tests/test_weak_lifecycle.hako
Normal file
62
local_tests/test_weak_lifecycle.hako
Normal file
@ -0,0 +1,62 @@
|
||||
// Advanced weak reference auto-nil demonstration
|
||||
|
||||
box Parent {
|
||||
init { name, child }
|
||||
|
||||
pack(parentName) {
|
||||
me.name = parentName
|
||||
me.child = new Child()
|
||||
me.child.setParent(me) // This creates a weak reference
|
||||
}
|
||||
|
||||
getChild() {
|
||||
return me.child
|
||||
}
|
||||
|
||||
getName() {
|
||||
return me.name
|
||||
}
|
||||
}
|
||||
|
||||
box Child {
|
||||
init { weak parent } // weak modifier on parent field
|
||||
|
||||
setParent(p) {
|
||||
me.parent = p
|
||||
}
|
||||
|
||||
getParentInfo() {
|
||||
// Check the weak reference
|
||||
return "Parent reference state checked"
|
||||
}
|
||||
|
||||
// Test method to manually check the weak field value
|
||||
checkWeakParent() {
|
||||
return me.parent
|
||||
}
|
||||
}
|
||||
|
||||
static box Main {
|
||||
main() {
|
||||
print("=== Weak Reference Auto-Nil Test ===")
|
||||
|
||||
local parent = new Parent("TestParent")
|
||||
local child = parent.getChild()
|
||||
|
||||
print("Step 1: Initial setup complete")
|
||||
print("Initial check: " + child.getParentInfo())
|
||||
|
||||
// Check initial weak reference value
|
||||
local parentRef = child.checkWeakParent()
|
||||
print("Initial parent ref exists: yes")
|
||||
|
||||
print("Step 2: Simulating parent 'drop' by setting to 0")
|
||||
parent = 0 // This should trigger weak reference invalidation
|
||||
|
||||
print("Step 3: Checking weak reference after parent drop")
|
||||
local parentRef2 = child.checkWeakParent()
|
||||
print("After drop parent ref exists: still checking")
|
||||
|
||||
return "weak reference lifecycle test completed"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user