aboutsummaryrefslogtreecommitdiff
path: root/tests/i
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-28 13:36:16 +0000
committer_ov4 <ov4@ov4.org>2026-10-28 13:36:16 +0000
commitb28384fed1ce638e8b00b72dba974e9fd7e55eb4 (patch)
treeb0b342b148c1d5b33197f7a59d0a7a7edb92af1c /tests/i
parentcaa88a9b36d9e1dfae40ecb31aee05bc2891fa17 (diff)
feat(overload): support default return types
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests/i')
-rw-r--r--tests/i/default-returns/case.json1
-rw-r--r--tests/i/default-returns/expected.txt12
-rw-r--r--tests/i/default-returns/notes.md7
-rw-r--r--tests/i/default-returns/program.cps54
4 files changed, 74 insertions, 0 deletions
diff --git a/tests/i/default-returns/case.json b/tests/i/default-returns/case.json
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/tests/i/default-returns/case.json
@@ -0,0 +1 @@
+{}
diff --git a/tests/i/default-returns/expected.txt b/tests/i/default-returns/expected.txt
new file mode 100644
index 0000000..3813090
--- /dev/null
+++ b/tests/i/default-returns/expected.txt
@@ -0,0 +1,12 @@
+2.5
+4
+3
+3
+2
+6.5
+7
+8.5
+9
+10.5
+11
+12
diff --git a/tests/i/default-returns/notes.md b/tests/i/default-returns/notes.md
new file mode 100644
index 0000000..973986f
--- /dev/null
+++ b/tests/i/default-returns/notes.md
@@ -0,0 +1,7 @@
+# Default returns
+
+Human review: pending. Expected output was independently traced by AI, not captured from cpsc.
+
+Basis: DEFAULT and return-type overloading are project extensions.
+
+Trace: Foo(INTEGER) defaults to REAL 2.5, while Foo(REAL) defaults to INTEGER 4. INTEGER assignment and cast select 3; a C_INT cast falls back to the default 2.5 then converts to 2. Get defaults to 6.5, member addition to 8.5, and global negation to 10.5; INTEGER assignments select 7, 9 and 11. The nested Foo call defaults to REAL, selecting Consume(REAL), which returns 12.
diff --git a/tests/i/default-returns/program.cps b/tests/i/default-returns/program.cps
new file mode 100644
index 0000000..a6a0694
--- /dev/null
+++ b/tests/i/default-returns/program.cps
@@ -0,0 +1,54 @@
+OVERLOAD FUNCTION Foo(X : INTEGER) RETURNS DEFAULT REAL
+ RETURN 2.5
+ENDFUNCTION
+OVERLOAD FUNCTION Foo(X : INTEGER) RETURNS INTEGER
+ RETURN 3
+ENDFUNCTION
+OVERLOAD FUNCTION Foo(X : REAL) RETURNS DEFAULT INTEGER
+ RETURN 4
+ENDFUNCTION
+OVERLOAD FUNCTION Foo(X : REAL) RETURNS REAL
+ RETURN 5.5
+ENDFUNCTION
+CLASS Box
+ Value : INTEGER
+ OVERLOAD FUNCTION Get() RETURNS DEFAULT REAL
+ RETURN 6.5
+ ENDFUNCTION
+ OVERLOAD FUNCTION Get() RETURNS INTEGER
+ RETURN 7
+ ENDFUNCTION
+ OVERLOAD FUNCTION OPERATOR+(Other : Box) RETURNS DEFAULT REAL
+ RETURN 8.5
+ ENDFUNCTION
+ OVERLOAD FUNCTION OPERATOR+(Other : Box) RETURNS INTEGER
+ RETURN 9
+ ENDFUNCTION
+ENDCLASS
+OVERLOAD FUNCTION OPERATOR-(X : Box) RETURNS DEFAULT REAL
+ RETURN 10.5
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR-(X : Box) RETURNS INTEGER
+ RETURN 11
+ENDFUNCTION
+OVERLOAD FUNCTION Consume(X : REAL) RETURNS INTEGER
+ RETURN 12
+ENDFUNCTION
+DECLARE B : Box
+DECLARE N : INTEGER
+OUTPUT Foo(1)
+OUTPUT Foo(1.0)
+N <- Foo(1)
+OUTPUT N
+OUTPUT (INTEGER)Foo(1)
+OUTPUT (C_INT)Foo(1)
+OUTPUT B.Get()
+N <- B.Get()
+OUTPUT N
+OUTPUT B + B
+N <- B + B
+OUTPUT N
+OUTPUT -B
+N <- -B
+OUTPUT N
+OUTPUT Consume(Foo(1))