Files
hakorune/local_tests/test_delegation_transparent.nyash
Moe Charm 83d3914e46 🚨 fix: フィールド差し替え時の危険な自動fini呼び出しを発見
現在の問題:
- me.field = newValue で古いfieldのfiniが自動で呼ばれる
- 共有参照を破壊する可能性(複数から参照されている場合)
- GC的な「おせっかい」でNyashの明示的哲学に反する

次の修正予定:
- フィールド差し替え:fini呼ばない(プログラマー責任)
- スコープ離脱時:fini呼ぶ(自然なリソース管理)
- Everything is Explicit の哲学を貫く

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-20 05:57:18 +09:00

67 lines
1.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 🎯 デリゲーション透過テスト
// 通常のユーザー定義Box継承
box Parent {
init { name, power }
birth(parentName) {
me.name = parentName
me.power = 100
print("👨‍👩‍👧‍👦 Parent誕生: " + me.name + " (power:" + me.power + ")")
}
attack() {
print("💥 " + me.name + "の攻撃!ダメージ:" + me.power)
}
}
box Child from Parent {
init { skill }
birth(childName) {
from Parent.birth(childName)
me.skill = "必殺技"
print("🧒 Child誕生完了スキル: " + me.skill)
}
override attack() {
print("⚡ " + me.skill + "発動!")
from Parent.attack()
}
}
// ビルトインBox継承pack透過テスト
box EnhancedString from StringBox {
init { prefix, suffix }
birth(text) {
pack StringBox(text) // ビルトイン継承(透過的)
me.prefix = "【"
me.suffix = "】"
print("📝 EnhancedString誕生: " + me.prefix + text + me.suffix)
}
enhanced() {
return me.prefix + me.toString() + me.suffix + "✨"
}
}
static box Main {
init { console }
main() {
me.console = new ConsoleBox()
me.console.log("🧪 デリゲーション透過テスト開始")
// ユーザー定義 → ユーザー定義
local child = new Child("太郎")
child.attack()
// ユーザー定義 → ビルトインpack透過
local enhanced = new EnhancedString("Hello")
print("結果: " + enhanced.enhanced())
return "全テスト完了"
}
}