Files
hakorune/apps/tests/phase285_weak_basic.hako
tomoaki 9227673ef7 feat(phase285w): Implement weak x unary operator syntax
Phase 285W-Syntax-0: Migrate weak reference syntax from function call
to unary operator for consistency and clarity.

**Changes**:
- Parser: Add UnaryOperator::Weak variant and parse_unary() handling
- MIR: Lower UnaryOp::Weak to emit_weak_new() (reuses existing path)
- AST: Add Weak to UnaryOperator enum + Display/JSON support
- Tests: Migrate 8 files from `weak(x)` to `weak x` syntax
  - 7 .hako test files updated
  - 1 smoke test shell script updated
- Cleanup: Remove obsolete weak(x) parser/MIR special cases
- Docs: Update Phase 285 README

**Syntax Change**:
- Old: `local w = weak(x)`  (function call)
- New: `local w = weak x`   (unary operator)

**Validation**: All migrated phase285* smoke tests pass (4/4 relevant)

**SSOT**: docs/reference/language/lifecycle.md

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-24 17:21:21 +09:00

36 lines
987 B
Plaintext

// Phase 285W-Syntax-0: WeakRef basic test with weak x syntax
// SSOT: docs/reference/language/lifecycle.md:179 - weak <expr>/weak_to_strong()
//
// Test: weak x creates WeakRef, weak_to_strong() returns Box when alive
// 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
local w = weak x
// 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
}
// Test 2: verify weak_to_strong returns same object (identity)
if y.x != 42 {
print("ng: weak_to_strong returned different object (expected x=42)")
return 1
}
print("ok: weak and weak_to_strong work correctly")
return 0
}
}