Phase 3 Complete: Parser extended with weak field support
Co-authored-by: moe-charm <217100418+moe-charm@users.noreply.github.com>
This commit is contained in:
50
test_weak_reference_basic.nyash
Normal file
50
test_weak_reference_basic.nyash
Normal file
@ -0,0 +1,50 @@
|
||||
// Basic weak reference test case
|
||||
|
||||
box Parent {
|
||||
init { child }
|
||||
|
||||
pack() {
|
||||
me.child = new Child()
|
||||
me.child.setParent(me) // This should create a weak reference
|
||||
}
|
||||
|
||||
getChild() {
|
||||
return me.child
|
||||
}
|
||||
}
|
||||
|
||||
box Child {
|
||||
init { weak parent } // weak modifier on parent field
|
||||
|
||||
setParent(p) {
|
||||
me.parent = p
|
||||
}
|
||||
|
||||
checkParent() {
|
||||
return me.parent != null
|
||||
}
|
||||
|
||||
getParentInfo() {
|
||||
if me.parent != null {
|
||||
return "Parent exists"
|
||||
} else {
|
||||
return "Parent is null (dropped)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static box Main {
|
||||
main() {
|
||||
local p = new Parent()
|
||||
local child = p.getChild()
|
||||
|
||||
print("Initial parent check: " + child.getParentInfo())
|
||||
|
||||
// When p goes out of scope, child.parent should automatically become null
|
||||
p = null
|
||||
|
||||
print("After parent dropped: " + child.getParentInfo())
|
||||
|
||||
return "weak reference test completed"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user