aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-17 08:34:42 +0000
committer_ov4 <ov4@ov4.org>2026-10-17 08:34:42 +0000
commitabd56ef20bc8061bbecec29edd1301d324c2cb34 (patch)
tree8da9a14372a60d4df8bf58693c62c187765e7240 /tests
parent59e3c50bcd58130e81e1f57b21d6e57b4d4aba6d (diff)
feat(classes): destroy stack objects at scope exit
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/i/class-delete/expected.txt12
-rw-r--r--tests/i/class-delete/notes.md2
-rw-r--r--tests/i/class-raii/case.json1
-rw-r--r--tests/i/class-raii/expected.txt12
-rw-r--r--tests/i/class-raii/notes.md5
-rw-r--r--tests/i/class-raii/program.cps49
-rw-r--r--tests/iii/class-destructor-private-error/case.json12
-rw-r--r--tests/iii/class-destructor-private-error/program.cps6
8 files changed, 99 insertions, 0 deletions
diff --git a/tests/i/class-delete/expected.txt b/tests/i/class-delete/expected.txt
index 85c4753..c7e7246 100644
--- a/tests/i/class-delete/expected.txt
+++ b/tests/i/class-delete/expected.txt
@@ -8,3 +8,15 @@ double caught
[Fatal] line 30: Invalid memory address (not an active allocation)
stack caught
leaf:2
+pair
+leaf:2
+leaf:1
+pair
+leaf:2
+leaf:1
+pair
+leaf:2
+leaf:1
+pair
+leaf:2
+leaf:1
diff --git a/tests/i/class-delete/notes.md b/tests/i/class-delete/notes.md
index c4e2638..efe1e52 100644
--- a/tests/i/class-delete/notes.md
+++ b/tests/i/class-delete/notes.md
@@ -3,3 +3,5 @@
Human review: pending. Expected output was independently traced by AI.
Explicit calls print only the outer method. Keyword DELETE prints outer, right, left. Invalid stack and stale heap addresses throw before any method runs. The array element uses an ordinary explicit method call.
+
+Normal main exit destroys Items[2], Items[1], Stack and the original Obj storage; each prints pair, leaf:2, leaf:1.
diff --git a/tests/i/class-raii/case.json b/tests/i/class-raii/case.json
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/tests/i/class-raii/case.json
@@ -0,0 +1 @@
+{}
diff --git a/tests/i/class-raii/expected.txt b/tests/i/class-raii/expected.txt
new file mode 100644
index 0000000..532f9db
--- /dev/null
+++ b/tests/i/class-raii/expected.txt
@@ -0,0 +1,12 @@
+destroy:31
+destroy:32
+destroy:20
+destroy:21
+destroy:50
+destroy:42
+destroy:41
+destroy:33
+destroy:2
+destroy:1
+main end
+destroy:100
diff --git a/tests/i/class-raii/notes.md b/tests/i/class-raii/notes.md
new file mode 100644
index 0000000..336e5cb
--- /dev/null
+++ b/tests/i/class-raii/notes.md
@@ -0,0 +1,5 @@
+# Stack lifetimes
+
+Human review: pending. Expected output was independently traced by AI.
+
+Loop re-declarations destroy 31 and 32 before reinitialization. Copy destroys local 20 then its shallow parameter copy 21. Early RETURN destroys record field 50, array elements 42 and 41, loop local 33, original rebound storage 2 and first local 1. Heap object 99 stays alive. Never is not constructed. Main destroys 100 after its final output.
diff --git a/tests/i/class-raii/program.cps b/tests/i/class-raii/program.cps
new file mode 100644
index 0000000..ff350f9
--- /dev/null
+++ b/tests/i/class-raii/program.cps
@@ -0,0 +1,49 @@
+CLASS Traced
+ Id : INTEGER
+ PROCEDURE NEW()
+ Id <- 0
+ ENDPROCEDURE
+ PROCEDURE DELETE()
+ OUTPUT "destroy:", Id
+ ENDPROCEDURE
+ENDCLASS
+TYPE Wrapped
+ DECLARE Item : Traced
+ENDTYPE
+PROCEDURE Copy(Value : Traced)
+ DECLARE Local : Traced
+ Local.Id <- 20
+ Value.Id <- 21
+ENDPROCEDURE
+PROCEDURE Work()
+ DECLARE First : Traced
+ First.Id <- 1
+ DECLARE Rebound : Traced
+ Rebound.Id <- 2
+ Rebound <- NEW Traced()
+ Rebound.Id <- 99
+ DECLARE I : INTEGER
+ FOR I <- 1 TO 3
+ DECLARE Again : Traced
+ Again.Id <- 3
+ Again.Id <- I + 30
+ NEXT I
+ DECLARE Arr : ARRAY[1:2] OF Plain
+ Arr[1].Item.Id <- 41
+ Arr[2].Item.Id <- 42
+ DECLARE Rec : Wrapped
+ Rec.Item.Id <- 50
+ CALL Copy(First)
+ IF TRUE THEN
+ RETURN
+ ENDIF
+ DECLARE Never : Traced
+ Never.Id <- 77
+ENDPROCEDURE
+CLASS Plain
+ Item : Traced
+ENDCLASS
+DECLARE Global : Traced
+ Global.Id <- 100
+CALL Work()
+OUTPUT "main end"
diff --git a/tests/iii/class-destructor-private-error/case.json b/tests/iii/class-destructor-private-error/case.json
new file mode 100644
index 0000000..4753d68
--- /dev/null
+++ b/tests/iii/class-destructor-private-error/case.json
@@ -0,0 +1,12 @@
+{
+ "errors": [
+ {
+ "reason": "private",
+ "line": 5
+ },
+ {
+ "reason": "private",
+ "line": 6
+ }
+ ]
+}
diff --git a/tests/iii/class-destructor-private-error/program.cps b/tests/iii/class-destructor-private-error/program.cps
new file mode 100644
index 0000000..8bd122c
--- /dev/null
+++ b/tests/iii/class-destructor-private-error/program.cps
@@ -0,0 +1,6 @@
+CLASS Secret
+PRIVATE PROCEDURE DELETE()
+ENDPROCEDURE
+ENDCLASS
+DECLARE Obj : Secret
+DELETE Obj