From 16231050058131860f710073c17d3bca7c6637eb Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 18 Oct 2026 06:05:53 +0000 Subject: feat(operators): support global binary operator overloads Resolve exact operand types and preserve declared operator return types. Reject implicit STRING to BOOLEAN conversion at typed expression boundaries. Co-Authored-By: Claude Opus 5.5 --- tests/iii/operator-global-errors/case.json | 24 ++++++++++++++++++++++++ tests/iii/operator-global-errors/notes.md | 3 +++ tests/iii/operator-global-errors/program.cps | 22 ++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 tests/iii/operator-global-errors/case.json create mode 100644 tests/iii/operator-global-errors/notes.md create mode 100644 tests/iii/operator-global-errors/program.cps (limited to 'tests/iii/operator-global-errors') diff --git a/tests/iii/operator-global-errors/case.json b/tests/iii/operator-global-errors/case.json new file mode 100644 index 0000000..eeb9965 --- /dev/null +++ b/tests/iii/operator-global-errors/case.json @@ -0,0 +1,24 @@ +{ + "errors": [ + { + "reason": "Cannot implicitly convert STRING to BOOLEAN", + "line": 12 + }, + { + "reason": "Operator \\+ cannot be applied to a record", + "line": 13 + }, + { + "reason": "requires a record, class or enum operand", + "line": 14 + }, + { + "reason": "Invalid operand count", + "line": 17 + }, + { + "reason": "cannot be redefined", + "line": 20 + } + ] +} diff --git a/tests/iii/operator-global-errors/notes.md b/tests/iii/operator-global-errors/notes.md new file mode 100644 index 0000000..24bb113 --- /dev/null +++ b/tests/iii/operator-global-errors/notes.md @@ -0,0 +1,3 @@ +# operator-global-errors + +Reject a STRING comparison result assigned to BOOLEAN, implicit INTEGER-to-REAL overload matching, builtin-only overloads, wrong arity and return-type-only duplicates. diff --git a/tests/iii/operator-global-errors/program.cps b/tests/iii/operator-global-errors/program.cps new file mode 100644 index 0000000..23bfae1 --- /dev/null +++ b/tests/iii/operator-global-errors/program.cps @@ -0,0 +1,22 @@ +TYPE Box +DECLARE Value : INTEGER +ENDTYPE +OVERLOAD FUNCTION OPERATOR+(a : Box, b : REAL) RETURNS INTEGER +RETURN 1 +ENDFUNCTION +OVERLOAD FUNCTION OPERATOR<(a : Box, b : Box) RETURNS STRING +RETURN "text" +ENDFUNCTION +DECLARE a : Box +DECLARE flag : BOOLEAN +flag <- a < a +OUTPUT a + 1 +OVERLOAD FUNCTION OPERATOR&(a : INTEGER, b : STRING) RETURNS STRING +RETURN b +ENDFUNCTION +OVERLOAD FUNCTION OPERATOR*(a : Box) RETURNS INTEGER +RETURN 1 +ENDFUNCTION +OVERLOAD FUNCTION OPERATOR+(a : Box, b : REAL) RETURNS REAL +RETURN 2.0 +ENDFUNCTION -- cgit v1.3.1-4-g156e