From e26a398082e30d8f7e884925116ce2ef092ed9c8 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Wed, 9 Sep 2026 12:00:54 +0000 Subject: [PATCH] test: cover unknown method return types --- CHANGELOG.md | 5 +++++ README.md | 2 ++ tests/typecheck_method_invalid_return_type_bad.claro | 5 +++++ tools/validate_typecheck_diagnostics.py | 3 +++ 4 files changed, 15 insertions(+) create mode 100644 tests/typecheck_method_invalid_return_type_bad.claro diff --git a/CHANGELOG.md b/CHANGELOG.md index 41204fb..d892a9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +### Validate unknown method return types + +- Added focused `claro typecheck` regression coverage for an object method declaring an unsupported `RETURNS` type such as `BANANA`. +- The release validator now checks function and method unknown-return-type diagnostics separately. + ### Diagnose unknown declared return types - `claro typecheck` now reports a learner-facing error when a function or object method declares an unsupported `RETURNS` type such as `BANANA`. diff --git a/README.md b/README.md index 9b318be..80e821a 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,8 @@ Return declarations must use a known Claro type. If the type name is misspelled, Function square declares an unknown return type BANANA. Use a Claro type such as NUMBER, TEXT, YESNO, LIST, or MAP. ``` +The same check applies to methods, so `Player.score RETURNS BANANA` reports `Method Player.score declares an unknown return type BANANA...` instead of allowing a misspelled type into a class definition. + The unknown-function diagnostic is validated for both modern `DO squre 4` and compatibility `CALL squre WITH 4` calls. Compatibility calls that leave `WITH` empty, such as `CALL greet WITH`, now count as zero arguments, so learners get the same missing-argument guidance as `DO greet` instead of the checker treating the blank as an argument. For functions with more than one checked parameter, Claro reports each mismatched argument with the parameter name: diff --git a/tests/typecheck_method_invalid_return_type_bad.claro b/tests/typecheck_method_invalid_return_type_bad.claro new file mode 100644 index 0000000..3d2f380 --- /dev/null +++ b/tests/typecheck_method_invalid_return_type_bad.claro @@ -0,0 +1,5 @@ +CLASS Player + TEACH score amount RETURNS BANANA + RETURN amount + END +END diff --git a/tools/validate_typecheck_diagnostics.py b/tools/validate_typecheck_diagnostics.py index 2ad23b5..34980bc 100644 --- a/tools/validate_typecheck_diagnostics.py +++ b/tools/validate_typecheck_diagnostics.py @@ -176,6 +176,9 @@ EXPECTED = { "tests/typecheck_invalid_return_type_bad.claro": [ "tests/typecheck_invalid_return_type_bad.claro:1: Function square declares an unknown return type BANANA. Use a Claro type such as NUMBER, TEXT, YESNO, LIST, or MAP.", ], + "tests/typecheck_method_invalid_return_type_bad.claro": [ + "tests/typecheck_method_invalid_return_type_bad.claro:2: Method Player.score declares an unknown return type BANANA. Use a Claro type such as NUMBER, TEXT, YESNO, LIST, or MAP.", + ], "tests/typecheck_object_field_unknown_object_bad.claro": [ "tests/typecheck_object_field_unknown_object_bad.claro:5: Object player is not known yet. Create it with NEW ClassName player before setting player.score.", ],