test: cover compatibility unknown field annotations
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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`
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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.",
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user