test: cover compatibility method field diagnostics

This commit is contained in:
Hermes Agent
2026-09-13 13:01:25 +00:00
parent 915bc7f1bc
commit ae41341a7d
6 changed files with 29 additions and 2 deletions
+5
View File
@@ -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.
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -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
@@ -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"
@@ -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"
+4
View File
@@ -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",