2025-12-24 17:21:21 +09:00
|
|
|
// Phase 285W-Syntax-0: WeakRef basic test with weak x syntax
|
|
|
|
|
// SSOT: docs/reference/language/lifecycle.md:179 - weak <expr>/weak_to_strong()
|
2025-12-24 07:44:50 +09:00
|
|
|
//
|
2025-12-24 17:21:21 +09:00
|
|
|
// Test: weak x creates WeakRef, weak_to_strong() returns Box when alive
|
2025-12-24 07:44:50 +09:00
|
|
|
// Note: Full drop semantics test deferred (needs GC/scope analysis)
|
|
|
|
|
// VM: PASS expected
|
|
|
|
|
// LLVM: SKIP (Phase 285A1)
|
|
|
|
|
|
|
|
|
|
box SomeBox {
|
|
|
|
|
x
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static box Main {
|
|
|
|
|
main() {
|
|
|
|
|
local x = new SomeBox()
|
|
|
|
|
x.x = 42
|
2025-12-24 17:21:21 +09:00
|
|
|
local w = weak x
|
2025-12-24 07:44:50 +09:00
|
|
|
|
|
|
|
|
// Test 1: weak_to_strong should succeed while x is alive
|
|
|
|
|
local y = w.weak_to_strong()
|
|
|
|
|
if y == null {
|
|
|
|
|
print("ng: weak_to_strong returned null while x alive")
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-24 17:21:21 +09:00
|
|
|
// Test 2: verify weak_to_strong returns same object (identity)
|
2025-12-24 07:44:50 +09:00
|
|
|
if y.x != 42 {
|
2025-12-24 17:21:21 +09:00
|
|
|
print("ng: weak_to_strong returned different object (expected x=42)")
|
2025-12-24 07:44:50 +09:00
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print("ok: weak and weak_to_strong work correctly")
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
}
|