From 55e783e2c3024accaaf9212fd82b68e09bbb0bd9 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Sat, 12 Sep 2026 16:21:24 +0000 Subject: [PATCH] test: cover compatibility method subtraction returns --- CHANGELOG.md | 5 +++++ docs/ADVANCED_STATIC_TYPING.md | 15 ++++++++++++++- docs/CURRENT_STATUS.md | 2 +- docs/ROADMAP.md | 2 +- ...ck_method_compat_return_subtraction_good.claro | 9 +++++++++ tools/validate_typecheck_diagnostics.py | 1 + 6 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 tests/typecheck_method_compat_return_subtraction_good.claro diff --git a/CHANGELOG.md b/CHANGELOG.md index 47ea6a8..5002d34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +### Validate compatibility method subtraction returns + +- Added focused positive typecheck coverage proving that the older `TEACH ... TAKES ... RETURNS NUMBER` / `LEARNED` method syntax accepts a numeric subtraction return after `CHECK TYPE` establishes the parameter type. +- Wired the fixture into the standalone typecheck validator and `claro validate`. + ### Validate numeric function subtraction returns - Added focused positive typecheck coverage proving that a typed function can return a numeric subtraction expression after `CHECK TYPE` establishes its parameter type. diff --git a/docs/ADVANCED_STATIC_TYPING.md b/docs/ADVANCED_STATIC_TYPING.md index 7e9d561..56f3be4 100644 --- a/docs/ADVANCED_STATIC_TYPING.md +++ b/docs/ADVANCED_STATIC_TYPING.md @@ -157,7 +157,20 @@ CLASS Player ENDCLASS ``` -The matching `CALL player.score WITH 4` path is included in focused validation. +This matching `CALL player.score WITH 4` path is included in focused validation. + +Compatibility methods support numeric subtraction in the same focused way: + +```claro +CLASS Player + TEACH score TAKES amount RETURNS NUMBER + CHECK TYPE amount IS NUMBER + RETURN amount - 2 + LEARNED +ENDCLASS +``` + +The matching `CALL player.score WITH 4` success path is included in focused validation alongside the modern method subtraction case. When a function declares a return type, `claro typecheck` accepts nested conditionals when every branch returns a value of that type: diff --git a/docs/CURRENT_STATUS.md b/docs/CURRENT_STATUS.md index 5e358b2..4f6cdf2 100644 --- a/docs/CURRENT_STATUS.md +++ b/docs/CURRENT_STATUS.md @@ -61,7 +61,7 @@ Ready now: Still needed: - Keep the focused typecheck validator's fixture list complete as new positive and negative examples are added. `claro validate` now executes the complete focused fixture matrix as well, so release validation cannot silently omit a listed typecheck example. - The expression checker now carries a known TEXT operand through all arithmetic operators so object-field and typed-function-return diagnostics do not hide addition, subtraction, multiplication, or division mistakes; focused numeric-subtraction, numeric-division, and numeric-multiplication positives plus text-operand addition, subtraction, multiplication, and division negatives protect this behavior. Typed-function return diagnostics now have focused subtraction and division positives alongside multiplication coverage. Text concatenation into a TEXT field has focused positive fixtures for both operand orders, including concatenation of two TEXT object fields. Each numeric operator names the text operand and explains that it needs NUMBER values. -- Method return validation now has focused positive subtraction and division fixtures alongside the existing arithmetic return coverage, including a compatibility `TAKES` / `LEARNED` division case, so checked NUMBER method parameters and numeric subtraction or division remain accepted by the release validator in both method spellings. +- Method return validation now has focused positive subtraction and division fixtures alongside the existing arithmetic return coverage, including compatibility `TAKES` / `LEARNED` subtraction and division cases, so checked NUMBER method parameters and numeric subtraction or division remain accepted by the release validator in both method spellings. - richer typed function signatures and return values beyond the focused simple function/method `RETURNS TYPE` check - type checking through branches and loops - richer object field type checking beyond simple direct assignments diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index d628bac..961052e 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -37,7 +37,7 @@ See `CURRENT_STATUS.md` for the detailed feature matrix. 4. Add small examples for each foundation feature before adding bigger syntax. The object-field foundation now includes positive and negative validation for field expressions such as `SET player.score player.name`, `SET player.score player.score + 1`, `SET player.name player.score + 1`, explicitly typed field assignments, explicit typed assignments to undeclared fields, simple and chained aliases such as `SET alias player`, `SET backup alias`, followed by `SET backup.score ...` or `CHECK TYPE backup.score IS ...`, chained aliases in object-method calls through both modern `DO` and compatibility `CALL ... WITH` forms (including a dedicated positive modern `DO` fixture), and arithmetic/text expression mismatches; typed containers also accept a map with nested type metadata when it is added to a `LIST OF MAP`; broader alias/control-flow checking remains planned. 5. Keep the focused typecheck validator complete: every `typecheck_*.claro` fixture, including positive fixtures, is now exercised by both the standalone diagnostic validator and `claro validate`. 6. Continue narrowing expression diagnostics: known TEXT operands now remain visible through arithmetic, with focused numeric-subtraction, numeric-division, and numeric-multiplication positives plus text-operand addition, subtraction, multiplication, and division coverage. Typed function returns now include positive subtraction and division examples alongside multiplication. Text concatenation into TEXT fields is covered in both operand orders, including field-to-field concatenation. Each numeric operator names the text operand and explains that it needs NUMBER values. `CHECK TYPE` also rejects misspelled expected type names. -- Keep typed method return examples balanced: numeric subtraction and division now have dedicated positive method fixtures in the focused validator, including a compatibility `TAKES` / `LEARNED` division case, alongside the existing method return mismatch diagnostics. +- Keep typed method return examples balanced: numeric subtraction and division now have dedicated positive method fixtures in the focused validator, including compatibility `TAKES` / `LEARNED` subtraction and division cases, alongside the existing method return mismatch diagnostics. - Keep IDE metadata aligned with the current beginner syntax: typed-language keywords such as `RETURNS`, `CHECK`, and `TYPE` are now included in the metadata used by editor helpers. - Keep compatibility-call coverage aligned with modern calls: empty `CALL object.method WITH` forms now have a focused missing-argument diagnostic fixture alongside the modern `DO object.method` case. Keep declared return types honest: `claro typecheck` now reports friendly diagnostics for unknown declared return types, mismatched, not-yet-inferable, and empty return expressions, declarations with no `RETURN`, and incomplete conditional branches, when a simple function or object method declares `RETURNS TYPE`; the declaration keyword is case-insensitive like other Claro keywords, with positive coverage in modern and compatibility function forms, including lowercase compatibility declarations and lowercase compatibility method declarations, plus a lowercase compatibility-method mismatch fixture. Complete `IF`/`ELSE` return branches, including nested complete conditionals in functions and methods, are accepted, and modern and compatibility function syntax plus compatibility method syntax are covered by focused fixtures. `CHECK TYPE` parameter metadata also informs arithmetic return-expression checking, including object methods; positive numeric multiplication return coverage now sits beside the mismatch fixtures; typed methods can also return class-declared fields by simple name, with positive and mismatch fixtures, and unknown method return expressions now have dedicated modern and compatibility diagnostic fixtures, and NUMBER return expressions with known TEXT arithmetic operands identify the operation and offending operand, including focused addition, subtraction, multiplication, and division coverage for functions and methods. Full path-sensitive analysis across nested conditionals and loops remains planned. diff --git a/tests/typecheck_method_compat_return_subtraction_good.claro b/tests/typecheck_method_compat_return_subtraction_good.claro new file mode 100644 index 0000000..7bd212d --- /dev/null +++ b/tests/typecheck_method_compat_return_subtraction_good.claro @@ -0,0 +1,9 @@ +CLASS Player + TEACH score TAKES amount RETURNS NUMBER + CHECK TYPE amount IS NUMBER + RETURN amount - 2 + LEARNED +ENDCLASS + +NEW Player player +CALL player.score WITH 4 diff --git a/tools/validate_typecheck_diagnostics.py b/tools/validate_typecheck_diagnostics.py index 857c12e..a1be91d 100644 --- a/tools/validate_typecheck_diagnostics.py +++ b/tools/validate_typecheck_diagnostics.py @@ -280,6 +280,7 @@ EXPECTED_OK = [ "tests/typecheck_method_compat_return_good.claro", "tests/typecheck_method_compat_lowercase_return_good.claro", "tests/typecheck_method_compat_return_division_good.claro", + "tests/typecheck_method_compat_return_subtraction_good.claro", "tests/typecheck_method_return_expression_good.claro", "tests/typecheck_method_return_multiplication_good.claro", "tests/typecheck_method_return_division_good.claro",