From ae41341a7d56cc48e8bc3edd9be0ef1dce3d18ff Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Sun, 13 Sep 2026 13:01:25 +0000 Subject: [PATCH] test: cover compatibility method field diagnostics --- CHANGELOG.md | 5 +++++ docs/CURRENT_STATUS.md | 2 +- docs/ROADMAP.md | 2 +- ...pecheck_method_compat_text_field_assignment_bad.claro | 9 +++++++++ ...echeck_method_compat_text_field_assignment_good.claro | 9 +++++++++ tools/validate_typecheck_diagnostics.py | 4 ++++ 6 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 tests/typecheck_method_compat_text_field_assignment_bad.claro create mode 100644 tests/typecheck_method_compat_text_field_assignment_good.claro diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bfa9a9..cac0fe8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ - Typecheck diagnostics for typed method-body field assignments now name the class method and arithmetic operation when a known TEXT operand is used in a NUMBER field update. +### Compatibility method field-assignment diagnostics + +- Added focused positive and negative typecheck fixtures for older `TEACH ... TAKES ...` / `LEARNED` methods that assign to typed class fields. +- Release validation now preserves the learner-facing `Class.method` name in these compatibility diagnostics. + ### Validate compatibility method multiplication diagnostics - Added focused negative typecheck coverage proving that the older `TAKES` / `LEARNED` method syntax identifies a TEXT operand in a NUMBER multiplication return and explains the required operand type. diff --git a/docs/CURRENT_STATUS.md b/docs/CURRENT_STATUS.md index e2ef7ad..a61d456 100644 --- a/docs/CURRENT_STATUS.md +++ b/docs/CURRENT_STATUS.md @@ -59,7 +59,7 @@ Ready now: Still needed: -- typed method-body assignments name the class method when a simple class field receives a known mismatched value or arithmetic expression, such as `SET name 123` inside `Player.rename` or `SET score score + name` inside `Player.add RETURNS NUMBER`; matching text and numeric assignment coverage is also validated +- typed method-body assignments name the class method when a simple class field receives a known mismatched value or arithmetic expression, such as `SET name 123` inside `Player.rename` or `SET score score + name` inside `Player.add RETURNS NUMBER`; matching text and numeric assignment coverage is also validated for modern and compatibility method syntax - 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 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. diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 9325f84..b6a4e72 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -42,7 +42,7 @@ See `CURRENT_STATUS.md` for the detailed feature matrix. - 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, including a dedicated compatibility-method multiplication success fixture; 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. Compatibility method subtraction diagnostics are also covered alongside the existing addition diagnostic. Full path-sensitive analysis across nested conditionals and loops remains planned. -7. Keep method-body field diagnostics learner-facing: typed methods now name the class method when a simple class field receives a known mismatched value or a known TEXT operand in a NUMBER expression, with matching text and numeric assignment coverage; broader control-flow and object-flow analysis remains planned. +7. Keep method-body field diagnostics learner-facing: typed methods now name the class method when a simple class field receives a known mismatched value or a known TEXT operand in a NUMBER expression, with matching text and numeric assignment coverage in modern and compatibility method syntax; broader control-flow and object-flow analysis remains planned. ### 1. Strong static types diff --git a/tests/typecheck_method_compat_text_field_assignment_bad.claro b/tests/typecheck_method_compat_text_field_assignment_bad.claro new file mode 100644 index 0000000..41da4e8 --- /dev/null +++ b/tests/typecheck_method_compat_text_field_assignment_bad.claro @@ -0,0 +1,9 @@ +CLASS Player + HAS name TEXT + TEACH rename TAKES replacement + SET name 123 + LEARNED +ENDCLASS + +NEW Player player +CALL player.rename WITH "Ada" \ No newline at end of file diff --git a/tests/typecheck_method_compat_text_field_assignment_good.claro b/tests/typecheck_method_compat_text_field_assignment_good.claro new file mode 100644 index 0000000..24509a9 --- /dev/null +++ b/tests/typecheck_method_compat_text_field_assignment_good.claro @@ -0,0 +1,9 @@ +CLASS Player + HAS name TEXT + TEACH rename TAKES replacement + SET name replacement + LEARNED +ENDCLASS + +NEW Player player +CALL player.rename WITH "Ada" \ No newline at end of file diff --git a/tools/validate_typecheck_diagnostics.py b/tools/validate_typecheck_diagnostics.py index 5e0fe07..de9cd3c 100644 --- a/tools/validate_typecheck_diagnostics.py +++ b/tools/validate_typecheck_diagnostics.py @@ -278,6 +278,9 @@ EXPECTED = { "tests/typecheck_method_text_field_assignment_bad.claro": [ "tests/typecheck_method_text_field_assignment_bad.claro:4: Type mismatch for field name in Player.rename: expected TEXT, but this value looks like NUMBER.", ], + "tests/typecheck_method_compat_text_field_assignment_bad.claro": [ + "tests/typecheck_method_compat_text_field_assignment_bad.claro:4: Type mismatch for field name in Player.rename: expected TEXT, but this value looks like NUMBER.", + ], } EXPECTED_OK = [ @@ -309,6 +312,7 @@ EXPECTED_OK = [ "tests/typecheck_method_unknown_return_expression_good.claro", "tests/typecheck_method_field_assignment_good.claro", "tests/typecheck_method_text_field_assignment_good.claro", + "tests/typecheck_method_compat_text_field_assignment_good.claro", "tests/typecheck_method_nested_branch_complete_good.claro", "tests/typecheck_function_multi_good.claro", "tests/typecheck_method_good.claro",