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 | |
| parent | 63109537383fa58c6a1db95f275d6b5de63b0015 (diff) | |
feat(types): support implicit single-argument constructors
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests')
| -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 | ||||
| -rw-r--r-- | tests/iii/implicit-conversion-errors/case.json | 24 | ||||
| -rw-r--r-- | tests/iii/implicit-conversion-errors/program.cps | 48 | ||||
| -rw-r--r-- | tests/iii/implicit-declaration-errors/case.json | 24 | ||||
| -rw-r--r-- | tests/iii/implicit-declaration-errors/program.cps | 21 |
8 files changed, 189 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 diff --git a/tests/iii/implicit-conversion-errors/case.json b/tests/iii/implicit-conversion-errors/case.json new file mode 100644 index 0000000..a004af2 --- /dev/null +++ b/tests/iii/implicit-conversion-errors/case.json @@ -0,0 +1,24 @@ +{ + "errors": [ + { + "line": 28, + "reason": "Cannot use a value of type INTEGER where ExplicitOnly is expected" + }, + { + "line": 29, + "reason": "Cannot use a value of type INTEGER where Second is expected" + }, + { + "line": 30, + "reason": "BYREF argument I to Ref must be of type First" + }, + { + "line": 41, + "reason": "Ambiguous call to Ambiguous" + }, + { + "line": 48, + "reason": "Cannot access private method NEW" + } + ] +} diff --git a/tests/iii/implicit-conversion-errors/program.cps b/tests/iii/implicit-conversion-errors/program.cps new file mode 100644 index 0000000..6297b16 --- /dev/null +++ b/tests/iii/implicit-conversion-errors/program.cps @@ -0,0 +1,48 @@ +CLASS ExplicitOnly + Value : INTEGER + PROCEDURE NEW(Number : INTEGER) + Value <- Number + ENDPROCEDURE +ENDCLASS +CLASS First + Value : INTEGER + IMPLICIT PROCEDURE NEW(Number : INTEGER) + Value <- Number + ENDPROCEDURE +ENDCLASS +CLASS Second + Value : INTEGER + IMPLICIT PROCEDURE NEW(Other : First) + Value <- Other.Value + ENDPROCEDURE +ENDCLASS +OVERLOAD PROCEDURE Choose(Value : First) +ENDPROCEDURE +OVERLOAD PROCEDURE Choose(Value : Second) +ENDPROCEDURE +PROCEDURE Ref(BYREF Value : First) +ENDPROCEDURE +DECLARE E : ExplicitOnly(1) +DECLARE S : Second +DECLARE I : INTEGER +E <- 1 +S <- 1 +CALL Ref(I) +CLASS Alternative + Value : INTEGER + IMPLICIT PROCEDURE NEW(Number : INTEGER) + Value <- Number + ENDPROCEDURE +ENDCLASS +OVERLOAD PROCEDURE Ambiguous(Value : First) +ENDPROCEDURE +OVERLOAD PROCEDURE Ambiguous(Value : Alternative) +ENDPROCEDURE +CALL Ambiguous(1) +CLASS Hidden + PRIVATE IMPLICIT PROCEDURE NEW(Number : INTEGER) + ENDPROCEDURE +ENDCLASS +PROCEDURE HiddenArg(Value : Hidden) +ENDPROCEDURE +CALL HiddenArg(1) diff --git a/tests/iii/implicit-declaration-errors/case.json b/tests/iii/implicit-declaration-errors/case.json new file mode 100644 index 0000000..3968b70 --- /dev/null +++ b/tests/iii/implicit-declaration-errors/case.json @@ -0,0 +1,24 @@ +{ + "errors": [ + { + "line": 2, + "reason": "IMPLICIT requires a CLASS constructor NEW with one BYVAL non-array parameter" + }, + { + "line": 6, + "reason": "IMPLICIT requires a CLASS constructor NEW with one BYVAL non-array parameter" + }, + { + "line": 10, + "reason": "IMPLICIT requires a CLASS constructor NEW with one BYVAL non-array parameter" + }, + { + "line": 14, + "reason": "IMPLICIT requires a CLASS constructor NEW with one BYVAL non-array parameter" + }, + { + "line": 18, + "reason": "IMPLICIT requires a CLASS constructor NEW with one BYVAL non-array parameter" + } + ] +} diff --git a/tests/iii/implicit-declaration-errors/program.cps b/tests/iii/implicit-declaration-errors/program.cps new file mode 100644 index 0000000..31cd23c --- /dev/null +++ b/tests/iii/implicit-declaration-errors/program.cps @@ -0,0 +1,21 @@ +CLASS Invalid + IMPLICIT PROCEDURE NEW() + ENDPROCEDURE +ENDCLASS +CLASS RefInvalid + IMPLICIT PROCEDURE NEW(BYREF Value : INTEGER) + ENDPROCEDURE +ENDCLASS +CLASS ArrayInvalid + IMPLICIT PROCEDURE NEW(Value : ARRAY OF INTEGER) + ENDPROCEDURE +ENDCLASS +CLASS MethodInvalid + IMPLICIT PROCEDURE Convert(Value : INTEGER) + ENDPROCEDURE +ENDCLASS +CLASS PairInvalid + IMPLICIT PROCEDURE NEW(A : INTEGER, B : INTEGER) + ENDPROCEDURE +ENDCLASS +OUTPUT 1 |
