From 75b2152f238dc5567d9b2557f856f8ba858325af Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Sun, 6 Sep 2026 16:09:10 +0000 Subject: [PATCH] test: cover chained object field assignments --- docs/ADVANCED_STATIC_TYPING.md | 15 +++++++++++++++ docs/CURRENT_STATUS.md | 2 +- ...typecheck_object_field_chained_alias_bad.claro | 8 ++++++++ tools/validate_typecheck_diagnostics.py | 3 +++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/typecheck_object_field_chained_alias_bad.claro diff --git a/docs/ADVANCED_STATIC_TYPING.md b/docs/ADVANCED_STATIC_TYPING.md index c6e3040..6fb3d22 100644 --- a/docs/ADVANCED_STATIC_TYPING.md +++ b/docs/ADVANCED_STATIC_TYPING.md @@ -74,6 +74,21 @@ Type mismatch for field alias.score: expected NUMBER, but this value looks like This is intentionally limited to simple aliases. Broader object-flow analysis through branches, loops, and complex expressions remains planned. +The same field-assignment check follows a second simple alias. This lets a learner use a more descriptive name without losing the class field type: + +```claro +SET backup alias +SET backup.score "ten" +``` + +Output: + +```text +Type mismatch for field backup.score: expected NUMBER, but this value looks like TEXT. +``` + +This remains limited to direct assignments through simple alias chains; control-flow and complex object-flow analysis are still planned. + `CHECK TYPE` also follows simple aliases for direct field metadata checks. This includes a second alias, so learners can give an object a more descriptive local name without losing the class field information: ```claro diff --git a/docs/CURRENT_STATUS.md b/docs/CURRENT_STATUS.md index 1a40401..c44c8fd 100644 --- a/docs/CURRENT_STATUS.md +++ b/docs/CURRENT_STATUS.md @@ -53,7 +53,7 @@ Ready now: - `TYPE OF` and `CHECK TYPE` - typed list/map checks through `claro typecheck`, including a nested `LIST OF MAP` insertion example - a narrow function/method argument check: `CHECK TYPE parameter IS TYPE` inside a function or simple object method lets `claro typecheck` accept correct checked calls, catch mismatched `DO`, `CALL ... WITH`, `DO object.method ...`, and compatibility `CALL object.method WITH ...` arguments, including checked methods that appear after another method in the same class, report missing checked function and method arguments, report missing unchecked arguments for simple functions and simple object methods, treat empty compatibility calls such as `CALL greet WITH` as missing-argument mistakes, catch extra arguments to simple functions and checked methods even when the checked method appears after another method in the same class, catch modern `DO` and compatibility `CALL ... WITH` calls to undeclared simple functions, explain when `DO object.method ...` or compatibility `CALL object.method WITH ...` happens before the object is created with `NEW` even if the method name is also wrong, and catch modern plus compatibility calls to undeclared object methods with a class-specific `TEACH` hint -- a narrow object-field assignment/check-type check for simple `NEW Class object` plus direct `SET object.field value` and `CHECK TYPE object.field IS TYPE` cases when the class declares `HAS field TYPE`; validation now covers correct NUMBER, TEXT, and YESNO direct assignments, explicitly typed field assignments, simple and chained object aliases including aliased `CHECK TYPE` metadata, aliased object-method calls including chained aliases, field-to-field, compound arithmetic field expressions, and arithmetic/text expression result types, direct `CHECK TYPE` metadata acceptance for NUMBER/TEXT/YESNO fields, negative NUMBER/TEXT/YESNO field `CHECK TYPE` metadata mismatches, NUMBER/TEXT/YESNO-expectation unknown-field `CHECK TYPE` diagnostics, missing-object field assignment and `CHECK TYPE` diagnostics, NUMBER/TEXT/YESNO wrong-type diagnostics, field collection when a `HAS` field appears after a simple method, NUMBER/TEXT/YESNO-valued unknown-field diagnostics for direct assignments to undeclared fields, numeric and text results from simple arithmetic/text expressions in object-field assignments, plus a plain beginner-facing unknown-field diagnostic when the assigned expression type is not inferable yet +- a narrow object-field assignment/check-type check for simple `NEW Class object` plus direct `SET object.field value` and `CHECK TYPE object.field IS TYPE` cases when the class declares `HAS field TYPE`; validation now covers correct NUMBER, TEXT, and YESNO direct assignments, explicitly typed field assignments, simple and chained object aliases for both field assignments and `CHECK TYPE` metadata, aliased object-method calls including chained aliases, field-to-field, compound arithmetic field expressions, and arithmetic/text expression result types, direct `CHECK TYPE` metadata acceptance for NUMBER/TEXT/YESNO fields, negative NUMBER/TEXT/YESNO field `CHECK TYPE` metadata mismatches, NUMBER/TEXT/YESNO-expectation unknown-field `CHECK TYPE` diagnostics, missing-object field assignment and `CHECK TYPE` diagnostics, NUMBER/TEXT/YESNO wrong-type diagnostics, field collection when a `HAS` field appears after a simple method, NUMBER/TEXT/YESNO-valued unknown-field diagnostics for direct assignments to undeclared fields, numeric and text results from simple arithmetic/text expressions in object-field assignments, plus a plain beginner-facing unknown-field diagnostic when the assigned expression type is not inferable yet Still needed: - richer typed function signatures and return values diff --git a/tests/typecheck_object_field_chained_alias_bad.claro b/tests/typecheck_object_field_chained_alias_bad.claro new file mode 100644 index 0000000..9bab070 --- /dev/null +++ b/tests/typecheck_object_field_chained_alias_bad.claro @@ -0,0 +1,8 @@ +CLASS Player + HAS score NUMBER +END + +NEW Player player +SET alias player +SET backup alias +SET backup.score "ten" diff --git a/tools/validate_typecheck_diagnostics.py b/tools/validate_typecheck_diagnostics.py index d8e918f..aae2260 100644 --- a/tools/validate_typecheck_diagnostics.py +++ b/tools/validate_typecheck_diagnostics.py @@ -146,6 +146,9 @@ EXPECTED = { "tests/typecheck_object_field_check_type_chained_alias_bad.claro": [ "tests/typecheck_object_field_check_type_chained_alias_bad.claro:8: Type check failed: expected TEXT, but backup.score looks like NUMBER.", ], + "tests/typecheck_object_field_chained_alias_bad.claro": [ + "tests/typecheck_object_field_chained_alias_bad.claro:8: Type mismatch for field backup.score: expected NUMBER, but this value looks like TEXT.", + ], "tests/typecheck_object_alias_method_bad.claro": [ "tests/typecheck_object_alias_method_bad.claro:12: Type mismatch for method Player.add: parameter points needs NUMBER, but this argument looks like TEXT.", ],