diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-30 14:23:32 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-30 14:23:32 +0000 |
| commit | 4cb0d9b196008bc55dbfcdac1f9211dbbc879895 (patch) | |
| tree | 0d95a2682ef26455483c4bb9222e1dff0d5c8e69 /tests/i/implicit-constructors | |
| parent | 63109537383fa58c6a1db95f275d6b5de63b0015 (diff) | |
feat(types): support implicit single-argument constructors
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests/i/implicit-constructors')
| -rw-r--r-- | tests/i/implicit-constructors/case.json | 1 | ||||
| -rw-r--r-- | tests/i/implicit-constructors/expected.txt | 5 | ||||
| -rw-r--r-- | tests/i/implicit-constructors/notes.md | 3 | ||||
| -rw-r--r-- | tests/i/implicit-constructors/program.cps | 63 |
4 files changed, 72 insertions, 0 deletions
diff --git a/tests/i/implicit-constructors/case.json b/tests/i/implicit-constructors/case.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/i/implicit-constructors/case.json @@ -0,0 +1 @@ +{} diff --git a/tests/i/implicit-constructors/expected.txt b/tests/i/implicit-constructors/expected.txt new file mode 100644 index 0000000..d360ce8 --- /dev/null +++ b/tests/i/implicit-constructors/expected.txt @@ -0,0 +1,5 @@ +7:8:201:6:9 +9 +TRUE +0 +0 diff --git a/tests/i/implicit-constructors/notes.md b/tests/i/implicit-constructors/notes.md new file mode 100644 index 0000000..cdcab87 --- /dev/null +++ b/tests/i/implicit-constructors/notes.md @@ -0,0 +1,3 @@ +# Implicit constructors + +Pending human review. Box counts constructions, copies and destruction. Assignments, BYVAL arguments, RETURN, operators and CASE use its INTEGER conversion. Pick selects its exact INTEGER overload. Exercise releases all objects; a later failing argument releases the pending converted Box before CATCH. diff --git a/tests/i/implicit-constructors/program.cps b/tests/i/implicit-constructors/program.cps new file mode 100644 index 0000000..d13236e --- /dev/null +++ b/tests/i/implicit-constructors/program.cps @@ -0,0 +1,63 @@ +GLOBAL + DECLARE Alive : INTEGER +ENDGLOBAL +CLASS Box + Value : INTEGER + OVERLOAD PROCEDURE NEW() + Alive <- Alive + 1 + ENDPROCEDURE + OVERLOAD IMPLICIT PROCEDURE NEW(Number : INTEGER) + Value <- Number + Alive <- Alive + 1 + ENDPROCEDURE + OVERLOAD PROCEDURE NEW(BYREF Other : Box) + Value <- Other.Value + Alive <- Alive + 1 + ENDPROCEDURE + PROCEDURE DELETE() + Alive <- Alive - 1 + ENDPROCEDURE +ENDCLASS +FUNCTION Read(Value : Box) RETURNS INTEGER + RETURN Value.Value +ENDFUNCTION +OVERLOAD FUNCTION Pick(Value : Box) RETURNS INTEGER + RETURN 100 + Value.Value +ENDFUNCTION +OVERLOAD FUNCTION Pick(Value : INTEGER) RETURNS INTEGER + RETURN 200 + Value +ENDFUNCTION +OVERLOAD FUNCTION Only(Value : Box) RETURNS INTEGER + RETURN Value.Value +ENDFUNCTION +OVERLOAD FUNCTION OPERATOR+(A : Box, B : Box) RETURNS INTEGER + RETURN A.Value + B.Value +ENDFUNCTION +OVERLOAD FUNCTION OPERATOR=(A : Box, B : Box) RETURNS BOOLEAN + RETURN A.Value = B.Value +ENDFUNCTION +FUNCTION Make() RETURNS Box + RETURN 9 +ENDFUNCTION +PROCEDURE Exercise() + DECLARE B : Box + B <- 7 + OUTPUT B.Value, ":", Read(8), ":", Pick(1), ":", Only(6), ":", B + 2 + OUTPUT Read(Make()) + CASE OF B + 7 : OUTPUT TRUE + OTHERWISE : OUTPUT FALSE + ENDCASE +ENDPROCEDURE +FUNCTION Fail() RETURNS INTEGER + THROW +ENDFUNCTION +PROCEDURE Pair(Value : Box, Number : INTEGER) +ENDPROCEDURE +CALL Exercise() +OUTPUT Alive +TRY + CALL Pair(1, Fail()) +CATCH + OUTPUT Alive +ENDTRY |
