From 30fced09675acfd2b9ab6db6be8359a70d3f0402 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 18 Oct 2026 08:09:06 +0000 Subject: feat(operators): allow member assignment operator overloads Co-Authored-By: Claude Opus 5.5 --- tests/i/operator-assign/case.json | 1 + tests/i/operator-assign/expected.txt | 7 +++++ tests/i/operator-assign/program.cps | 39 ++++++++++++++++++++++++++++ tests/iii/operator-assign-global/case.json | 1 + tests/iii/operator-assign-global/program.cps | 3 +++ 5 files changed, 51 insertions(+) create mode 100644 tests/i/operator-assign/case.json create mode 100644 tests/i/operator-assign/expected.txt create mode 100644 tests/i/operator-assign/program.cps create mode 100644 tests/iii/operator-assign-global/case.json create mode 100644 tests/iii/operator-assign-global/program.cps (limited to 'tests') diff --git a/tests/i/operator-assign/case.json b/tests/i/operator-assign/case.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/i/operator-assign/case.json @@ -0,0 +1 @@ +{} diff --git a/tests/i/operator-assign/expected.txt b/tests/i/operator-assign/expected.txt new file mode 100644 index 0000000..aaf45ba --- /dev/null +++ b/tests/i/operator-assign/expected.txt @@ -0,0 +1,7 @@ +copy:3 +copy:3 +copy:7 +copy:7 +copy:5 +copy:7 +7:7:7:5 diff --git a/tests/i/operator-assign/program.cps b/tests/i/operator-assign/program.cps new file mode 100644 index 0000000..d534806 --- /dev/null +++ b/tests/i/operator-assign/program.cps @@ -0,0 +1,39 @@ +CLASS Value + N : INTEGER + OVERLOAD PROCEDURE NEW() + ENDPROCEDURE + OVERLOAD PROCEDURE NEW(BYREF Other : Value) + N <- Other.N + ENDPROCEDURE + OVERLOAD PROCEDURE OPERATOR<-(BYREF Other : Value) + OUTPUT "copy:", Other.N + N <- Other.N + ENDPROCEDURE + OVERLOAD PROCEDURE OPERATOR<-(Text : C_STRING) + N <- LENGTH((STRING)Text) + ENDPROCEDURE +ENDCLASS +FUNCTION Make() RETURNS Value + DECLARE X : Value + X.N <- 7 + RETURN X +ENDFUNCTION +TYPE ValuePtr = ^Value +TYPE Box + DECLARE Item : Value +ENDTYPE +DECLARE A : Value +DECLARE B : Value +A.N <- 3 +B <- A +B <- B +B <- Make() +A <- (C_STRING)"hello" +DECLARE R : Box +R.Item <- B +DECLARE Items : ARRAY[1:1] OF Value +Items[1] <- A +DECLARE P : ValuePtr +P <- ^A +P^ <- B +OUTPUT A.N, ":", B.N, ":", R.Item.N, ":", Items[1].N diff --git a/tests/iii/operator-assign-global/case.json b/tests/iii/operator-assign-global/case.json new file mode 100644 index 0000000..7a2e21d --- /dev/null +++ b/tests/iii/operator-assign-global/case.json @@ -0,0 +1 @@ +{"errors":[{"reason":"Assignment operator must be","line":1}]} diff --git a/tests/iii/operator-assign-global/program.cps b/tests/iii/operator-assign-global/program.cps new file mode 100644 index 0000000..6f6454e --- /dev/null +++ b/tests/iii/operator-assign-global/program.cps @@ -0,0 +1,3 @@ +OVERLOAD PROCEDURE OPERATOR<-(X : INTEGER) +ENDPROCEDURE +OUTPUT 0 -- cgit v1.3.1-4-g156e