aboutsummaryrefslogtreecommitdiff
path: root/tests/i
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-18 06:09:01 +0000
committer_ov4 <ov4@ov4.org>2026-10-18 06:09:01 +0000
commitb17f101cfc75565f9991c856ec62f1e17b0ab104 (patch)
tree6c925f06c45dbaa557a0451cfca33f17be71ec67 /tests/i
parent16231050058131860f710073c17d3bca7c6637eb (diff)
feat(operators): add member and unary overloads with explicit calls
Select member and global candidates together, enforce private access, and reuse argument marshalling. Materialize temporary receivers for chaining and register them for the existing object cleanup mechanism. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests/i')
-rw-r--r--tests/i/operator-members/case.json1
-rw-r--r--tests/i/operator-members/expected.txt12
-rw-r--r--tests/i/operator-members/notes.md7
-rw-r--r--tests/i/operator-members/program.cps66
4 files changed, 86 insertions, 0 deletions
diff --git a/tests/i/operator-members/case.json b/tests/i/operator-members/case.json
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/tests/i/operator-members/case.json
@@ -0,0 +1 @@
+{}
diff --git a/tests/i/operator-members/expected.txt b/tests/i/operator-members/expected.txt
new file mode 100644
index 0000000..24ab52b
--- /dev/null
+++ b/tests/i/operator-members/expected.txt
@@ -0,0 +1,12 @@
+9
+-3
+negated
+3!
+8
+8
+8
+6
+make
+number
+6
+caught
diff --git a/tests/i/operator-members/notes.md b/tests/i/operator-members/notes.md
new file mode 100644
index 0000000..2b741c9
--- /dev/null
+++ b/tests/i/operator-members/notes.md
@@ -0,0 +1,7 @@
+# operator-members
+
+Human review: pending. Expected output was independently traced by AI, not captured from cpsc.
+
+Basis: operator overloading is a project extension; arguments match exact types.
+
+Trace: chained additions produce 3 + 2 + 4 = 9. Unary minus returns -3; NOT deliberately returns negated. A method can use its private concatenation operator, yielding 3!. Box addition modifies the original receiver from 3 to 8. Explicit member addition then global subtraction yields 8; explicit global subtraction yields 6. Discarded unary/global calls produce no output. MakeBox prints make exactly once, then Number prints number exactly once; their result has value 4 + 2 = 6. A throwing global multiplication reaches CATCH.
diff --git a/tests/i/operator-members/program.cps b/tests/i/operator-members/program.cps
new file mode 100644
index 0000000..d17184c
--- /dev/null
+++ b/tests/i/operator-members/program.cps
@@ -0,0 +1,66 @@
+CLASS Box
+Value : INTEGER
+OVERLOAD FUNCTION OPERATOR+(rhs : INTEGER) RETURNS Box
+DECLARE result : Box
+result.Value <- Value + rhs
+RETURN result
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR+(rhs : Box) RETURNS INTEGER
+Value <- Value + rhs.Value
+RETURN Value
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR-() RETURNS INTEGER
+RETURN -Value
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR NOT() RETURNS STRING
+RETURN "negated"
+ENDFUNCTION
+PRIVATE OVERLOAD FUNCTION OPERATOR&(rhs : STRING) RETURNS STRING
+RETURN NUM_TO_STR(Value) & rhs
+ENDFUNCTION
+FUNCTION Describe() RETURNS STRING
+RETURN this & "!"
+ENDFUNCTION
+ENDCLASS
+OVERLOAD FUNCTION OPERATOR-(lhs : Box, rhs : INTEGER) RETURNS INTEGER
+RETURN lhs.Value - rhs
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR*(lhs : Box, rhs : Box) RETURNS INTEGER
+THROW
+RETURN 0
+ENDFUNCTION
+FUNCTION MakeBox() RETURNS Box
+OUTPUT "make"
+DECLARE result : Box
+result.Value <- 4
+RETURN result
+ENDFUNCTION
+FUNCTION Number() RETURNS INTEGER
+OUTPUT "number"
+RETURN 2
+ENDFUNCTION
+DECLARE a : Box
+DECLARE b : Box
+DECLARE result : Box
+a.Value <- 3
+b.Value <- 5
+result <- (a + 2) + 4
+OUTPUT result.Value
+OUTPUT -a
+OUTPUT NOT a
+OUTPUT a.Describe()
+OUTPUT a + b
+OUTPUT a.Value
+OUTPUT a.OPERATOR+(1) - 1
+OUTPUT OPERATOR-(a, 2)
+CALL a.OPERATOR-( )
+a.OPERATOR-( )
+CALL OPERATOR-(a, 1)
+OPERATOR-(a, 1)
+result <- MakeBox() + Number()
+OUTPUT result.Value
+TRY
+OUTPUT a * b
+CATCH
+OUTPUT "caught"
+ENDTRY