From 88c684da37c40f09359a6ecbb2facf9a64a85cf6 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Tue, 15 Sep 2026 12:38:49 +0000 Subject: [PATCH] test: cover compatibility inline field annotations --- CHANGELOG.md | 5 +++++ README.md | 2 +- docs/CURRENT_STATUS.md | 2 +- docs/ROADMAP.md | 1 + ...eck_method_compat_inline_field_annotation_bad.claro | 10 ++++++++++ ...ck_method_compat_inline_field_annotation_good.claro | 10 ++++++++++ tools/validate_typecheck_diagnostics.py | 4 ++++ 7 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 tests/typecheck_method_compat_inline_field_annotation_bad.claro create mode 100644 tests/typecheck_method_compat_inline_field_annotation_good.claro diff --git a/CHANGELOG.md b/CHANGELOG.md index b6dc84c..d285ce6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ - A mismatch such as `SET score TEXT 10` inside a method for `HAS score NUMBER` explains both types and suggests the class-declared type. - Added positive and negative fixtures to the complete typecheck validation matrix. +### Validate compatibility inline method-field annotations + +- Added matching positive and negative coverage for `TEACH ... TAKES ...` / `LEARNED` methods. +- Release validation now protects the same class-declared-type diagnostic for older compatibility lessons. + - Added focused modern-method coverage for the learner-facing diagnostic produced when an undeclared field is assigned from an expression whose type is not inferable yet. ## Unreleased diff --git a/README.md b/README.md index c4d96fb..103f9d2 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ OBJECT CLASS player AS kind OBJECT FIELDS player AS fields ``` -Inside a method, an inline field type must agree with the class declaration. For example, `HAS score NUMBER` must not be assigned with `SET score TEXT 10`; `claro typecheck` explains the conflict and suggests `NUMBER`. +Inside a method, an inline field type must agree with the class declaration. For example, `HAS score NUMBER` must not be assigned with `SET score TEXT 10`; `claro typecheck` explains the conflict and suggests `NUMBER`. The same check applies to older `TEACH ... TAKES ...` / `LEARNED` methods, so compatibility lessons get the same feedback. ## Static type safety diff --git a/docs/CURRENT_STATUS.md b/docs/CURRENT_STATUS.md index a63d705..905d949 100644 --- a/docs/CURRENT_STATUS.md +++ b/docs/CURRENT_STATUS.md @@ -68,7 +68,7 @@ Still needed: - type checking through branches and loops - richer object field type checking beyond simple direct assignments - typed imports/modules -- inline method-field annotations must agree with the class `HAS` declaration; conflicting annotations now get a repair-oriented diagnostic even when the value's inferred type is otherwise correct. +- inline method-field annotations must agree with the class `HAS` declaration in both modern `TEACH` / `END` and compatibility `TAKES` / `LEARNED` methods; conflicting annotations now get a repair-oriented diagnostic even when the value's inferred type is otherwise correct. Good starting docs: - `ADVANCED_STATIC_TYPING.md` diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 4c32fc6..1199f46 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -49,6 +49,7 @@ Keep declared return types honest: `claro typecheck` now reports friendly diagno 8b. Keep compatibility method-body text expressions aligned: `TAKES` / `LEARNED` methods now have positive TEXT concatenation coverage in both operand orders beside the modern `TEACH` / `END` examples. 8c. Keep explicit method-field annotations aligned with class declarations: `SET score TEXT "oops"` inside a method with `HAS score NUMBER` now reports the declared field mismatch instead of accepting the inline annotation; broader annotation consistency remains planned. 8d. Keep inline method-field annotations consistent with `HAS` declarations: `claro typecheck` now rejects a conflicting annotation even when the assigned value itself has the class-declared type, and explains which type to use. +8e. Keep inline method-field annotation coverage aligned across syntax generations: compatibility `TAKES` / `LEARNED` methods now have matching positive and negative fixtures, so older lessons retain the same class-declared-type guidance. ### 1. Strong static types diff --git a/tests/typecheck_method_compat_inline_field_annotation_bad.claro b/tests/typecheck_method_compat_inline_field_annotation_bad.claro new file mode 100644 index 0000000..baaff1c --- /dev/null +++ b/tests/typecheck_method_compat_inline_field_annotation_bad.claro @@ -0,0 +1,10 @@ +CLASS Player + HAS score NUMBER + + TEACH set_score TAKES value + SET score TEXT 10 + LEARNED +END + +NEW Player player +CALL player.set_score WITH 10 diff --git a/tests/typecheck_method_compat_inline_field_annotation_good.claro b/tests/typecheck_method_compat_inline_field_annotation_good.claro new file mode 100644 index 0000000..dfcc9c0 --- /dev/null +++ b/tests/typecheck_method_compat_inline_field_annotation_good.claro @@ -0,0 +1,10 @@ +CLASS Player + HAS score NUMBER + + TEACH set_score TAKES value + SET score NUMBER 10 + LEARNED +END + +NEW Player player +CALL player.set_score WITH 10 diff --git a/tools/validate_typecheck_diagnostics.py b/tools/validate_typecheck_diagnostics.py index ee39c23..8cdb2bc 100644 --- a/tools/validate_typecheck_diagnostics.py +++ b/tools/validate_typecheck_diagnostics.py @@ -299,6 +299,9 @@ EXPECTED = { "tests/typecheck_method_inline_field_annotation_bad.claro": [ "tests/typecheck_method_inline_field_annotation_bad.claro:5: Type mismatch for field score in Player.set_score: class declares NUMBER, but this assignment says TEXT. Use NUMBER for score.", ], + "tests/typecheck_method_compat_inline_field_annotation_bad.claro": [ + "tests/typecheck_method_compat_inline_field_annotation_bad.claro:5: Type mismatch for field score in Player.set_score: class declares NUMBER, but this assignment says TEXT. Use NUMBER for score.", + ], "tests/typecheck_method_unknown_field_expression_bad.claro": [ "tests/typecheck_method_unknown_field_expression_bad.claro:5: Object Player has no field level. Check the field name or add the field to the class with the right type.", ], @@ -372,6 +375,7 @@ EXPECTED_OK = [ "tests/typecheck_method_compat_yesno_field_check_type_good.claro", "tests/typecheck_method_yesno_field_check_type_good.claro", "tests/typecheck_method_inline_field_annotation_good.claro", + "tests/typecheck_method_compat_inline_field_annotation_good.claro", "tests/typecheck_method_nested_branch_complete_good.claro", "tests/typecheck_function_multi_good.claro", "tests/typecheck_method_good.claro",