test: cover compatibility inline field annotations

This commit is contained in:
Hermes Agent
2026-09-15 12:38:49 +00:00
parent 0a31646f5d
commit 88c684da37
7 changed files with 32 additions and 2 deletions
+5
View File
@@ -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. - 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. - 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. - 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 ## Unreleased
+1 -1
View File
@@ -109,7 +109,7 @@ OBJECT CLASS player AS kind
OBJECT FIELDS player AS fields 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 ## Static type safety
+1 -1
View File
@@ -68,7 +68,7 @@ Still needed:
- type checking through branches and loops - type checking through branches and loops
- richer object field type checking beyond simple direct assignments - richer object field type checking beyond simple direct assignments
- typed imports/modules - 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: Good starting docs:
- `ADVANCED_STATIC_TYPING.md` - `ADVANCED_STATIC_TYPING.md`
+1
View File
@@ -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. 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. 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. 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 ### 1. Strong static types
@@ -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
@@ -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
+4
View File
@@ -299,6 +299,9 @@ EXPECTED = {
"tests/typecheck_method_inline_field_annotation_bad.claro": [ "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_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": [
"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.", "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_compat_yesno_field_check_type_good.claro",
"tests/typecheck_method_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_inline_field_annotation_good.claro",
"tests/typecheck_method_compat_inline_field_annotation_good.claro",
"tests/typecheck_method_nested_branch_complete_good.claro", "tests/typecheck_method_nested_branch_complete_good.claro",
"tests/typecheck_function_multi_good.claro", "tests/typecheck_function_multi_good.claro",
"tests/typecheck_method_good.claro", "tests/typecheck_method_good.claro",