From ea15117a1fe75e473fe107d34fe86f4752561853 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Fri, 18 Sep 2026 19:33:51 +0000 Subject: [PATCH] test: cover extra return tokens in methods --- README.md | 2 ++ docs/CURRENT_STATUS.md | 2 +- docs/ROADMAP.md | 1 + tests/typecheck_method_compat_return_extra_tokens_bad.claro | 6 ++++++ tests/typecheck_method_return_extra_tokens_bad.claro | 6 ++++++ tools/validate_typecheck_diagnostics.py | 6 ++++++ 6 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/typecheck_method_compat_return_extra_tokens_bad.claro create mode 100644 tests/typecheck_method_return_extra_tokens_bad.claro diff --git a/README.md b/README.md index 8d17cb8..01be603 100644 --- a/README.md +++ b/README.md @@ -284,6 +284,8 @@ END Function square has extra text after return value amount. Keep only one expression after RETURN. ``` +The same focused repair applies to modern and compatibility object methods, and names the complete method such as `Player.total`. + If a function or method declares `RETURNS TYPE` but contains no `RETURN`, the checker points out the missing statement: ```text diff --git a/docs/CURRENT_STATUS.md b/docs/CURRENT_STATUS.md index 06aeae1..43ad73e 100644 --- a/docs/CURRENT_STATUS.md +++ b/docs/CURRENT_STATUS.md @@ -54,7 +54,7 @@ Ready now: - `CHECK TYPE` gives a direct repair hint when the learner forgets the `IS` keyword, for example `CHECK TYPE score` reports `CHECK TYPE needs IS. Try: CHECK TYPE score IS NUMBER.` - `CHECK TYPE` gives a direct repair hint when `IS` has no expected type, for example `CHECK TYPE score IS` reports `CHECK TYPE score needs a type after IS. Try: CHECK TYPE score IS NUMBER.` - `CHECK TYPE` explains when the learner leaves out the expression as well, for example bare `CHECK TYPE` reports `CHECK TYPE needs an expression, IS, and a type. Try: CHECK TYPE score IS NUMBER.` -- typed function and method returns reject simple extra tokens after a return value with a direct repair hint, such as `RETURN amount extra` reporting `Keep only one expression after RETURN.` +- typed function and method returns reject simple extra tokens after a return value with a direct repair hint, such as `RETURN amount extra` reporting `Keep only one expression after RETURN.` This is covered for modern functions and both modern and compatibility object methods. - `CHECK TYPE` explains when `IS` is present but the expression is missing, for example `CHECK TYPE IS NUMBER` reports `CHECK TYPE needs an expression before IS. Try: CHECK TYPE score IS NUMBER.` - `CHECK TYPE` rejects extra words after a valid expected type with a direct repair hint, so `CHECK TYPE score IS NUMBER TEXT` explains that only one type belongs in the check - `CHECK TYPE` rejects unknown expected type names with a beginner-facing list of supported types diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index c7e1308..7b946b5 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -84,6 +84,7 @@ Keep declared return types honest: `claro typecheck` now reports friendly diagno 8q.8. Keep typed `TEACH` declarations complete: a bare `RETURNS` now gets a direct repair hint naming the missing type and showing a supported example such as `NUMBER`. 8q.9. Keep missing return-type diagnostics aligned across functions and methods: modern and compatibility methods now name the complete `Class.method` identity when `RETURNS` has no type, with focused fixtures in the typecheck and release validation matrices. 8q.10. Keep return statements beginner-readable: typed returns now identify simple extra tokens after a value and explain that `RETURN` accepts one expression, with focused release validation coverage. +8q.11. Keep extra-token return diagnostics aligned across syntax generations: modern and compatibility object methods now have focused fixtures for `RETURN value extra`, so method errors keep the class-and-method name and the same repair hint as function errors. ### 1. Strong static types diff --git a/tests/typecheck_method_compat_return_extra_tokens_bad.claro b/tests/typecheck_method_compat_return_extra_tokens_bad.claro new file mode 100644 index 0000000..dddac36 --- /dev/null +++ b/tests/typecheck_method_compat_return_extra_tokens_bad.claro @@ -0,0 +1,6 @@ +CLASS Player + HAS score NUMBER + TEACH total TAKES amount RETURNS NUMBER + RETURN amount extra + LEARNED +END diff --git a/tests/typecheck_method_return_extra_tokens_bad.claro b/tests/typecheck_method_return_extra_tokens_bad.claro new file mode 100644 index 0000000..40c913e --- /dev/null +++ b/tests/typecheck_method_return_extra_tokens_bad.claro @@ -0,0 +1,6 @@ +CLASS Player + HAS score NUMBER + TEACH total RETURNS NUMBER + RETURN 1 extra + END +END diff --git a/tools/validate_typecheck_diagnostics.py b/tools/validate_typecheck_diagnostics.py index 9d5ac39..8779932 100644 --- a/tools/validate_typecheck_diagnostics.py +++ b/tools/validate_typecheck_diagnostics.py @@ -70,6 +70,12 @@ EXPECTED = { "tests/typecheck_function_return_extra_tokens_bad.claro": [ "tests/typecheck_function_return_extra_tokens_bad.claro:2: Function square has extra text after return value amount. Keep only one expression after RETURN.", ], + "tests/typecheck_method_return_extra_tokens_bad.claro": [ + "tests/typecheck_method_return_extra_tokens_bad.claro:4: Method Player.total has extra text after return value 1. Keep only one expression after RETURN.", + ], + "tests/typecheck_method_compat_return_extra_tokens_bad.claro": [ + "tests/typecheck_method_compat_return_extra_tokens_bad.claro:4: Method Player.total has extra text after return value amount. Keep only one expression after RETURN.", + ], "tests/typecheck_function_lowercase_return_bad.claro": [ "tests/typecheck_function_lowercase_return_bad.claro:2: Type mismatch for return from square: expected NUMBER, but this value looks like TEXT.", ],