diff --git a/CHANGELOG.md b/CHANGELOG.md index a7f9fb3..8da29bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +### Validate compatibility unknown inline method-field annotations + +- Added focused coverage proving that compatibility `TAKES` / `LEARNED` methods reject unknown inline field annotations with the same repair-oriented diagnostic as modern methods. + ### Diagnose unknown inline method-field annotations - `claro typecheck` now rejects unknown inline field annotations such as `BANANA` and suggests the class-declared `HAS` type. diff --git a/README.md b/README.md index 71155be..f211c54 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,7 @@ 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`. The same check applies to older `TEACH ... TAKES ...` / `LEARNED` methods, so compatibility lessons get the same feedback. If an inline method-field annotation is not a Claro type, `claro typecheck` names the field and method and suggests the class declaration. For example, `SET score AS BANANA TO 10` reports that `BANANA` is unknown and recommends `NUMBER`. +The same diagnostic is covered for older `TEACH ... TAKES ...` / `LEARNED` methods, so compatibility lessons do not silently accept misspelled field types. ## Static type safety diff --git a/docs/CURRENT_STATUS.md b/docs/CURRENT_STATUS.md index 05913b0..3466bc3 100644 --- a/docs/CURRENT_STATUS.md +++ b/docs/CURRENT_STATUS.md @@ -70,6 +70,7 @@ Still needed: - typed imports/modules - 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. - inline method-field annotations also reject unknown names such as `BANANA`, naming the field and method and suggesting the class-declared type. +- compatibility `TEACH ... TAKES ...` / `LEARNED` methods have matching validation for unknown inline field annotations, so older lessons receive the same repair guidance. Good starting docs: - `ADVANCED_STATIC_TYPING.md` diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index a5907f1..f6a303e 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -51,6 +51,7 @@ Keep declared return types honest: `claro typecheck` now reports friendly diagno 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. 8f. Keep inline method-field annotations learner-facing: an unknown annotation such as `BANANA` now names the field and method and suggests the `HAS` type instead of silently treating the annotation as an expression. +8g. Keep unknown inline method-field annotation diagnostics aligned across syntax generations: compatibility `TAKES` / `LEARNED` methods now have matching focused coverage for misspelled annotations. ### 1. Strong static types diff --git a/tests/typecheck_method_compat_inline_field_annotation_unknown_type_bad.claro b/tests/typecheck_method_compat_inline_field_annotation_unknown_type_bad.claro new file mode 100644 index 0000000..9b9ab40 --- /dev/null +++ b/tests/typecheck_method_compat_inline_field_annotation_unknown_type_bad.claro @@ -0,0 +1,10 @@ +CLASS Player + HAS score NUMBER + + TEACH set_score TAKES value + SET score AS BANANA TO 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 ce0138e..ba06f6c 100644 --- a/tools/validate_typecheck_diagnostics.py +++ b/tools/validate_typecheck_diagnostics.py @@ -305,6 +305,9 @@ EXPECTED = { "tests/typecheck_method_inline_field_annotation_unknown_type_bad.claro": [ "tests/typecheck_method_inline_field_annotation_unknown_type_bad.claro:5: Field score in Player.set_score needs a known type such as NUMBER, TEXT, or YESNO, but BANANA is not a Claro type. Use NUMBER for score.", ], + "tests/typecheck_method_compat_inline_field_annotation_unknown_type_bad.claro": [ + "tests/typecheck_method_compat_inline_field_annotation_unknown_type_bad.claro:5: Field score in Player.set_score needs a known type such as NUMBER, TEXT, or YESNO, but BANANA is not a Claro type. 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.", ],