diff --git a/docs/ADVANCED_STATIC_TYPING.md b/docs/ADVANCED_STATIC_TYPING.md index 7d6e592..cfba194 100644 --- a/docs/ADVANCED_STATIC_TYPING.md +++ b/docs/ADVANCED_STATIC_TYPING.md @@ -102,6 +102,8 @@ Function square's return value could not be understood yet. Use a NUMBER express Use a known typed value, such as a parameter checked with `CHECK TYPE`, while broader expression inference remains future work. +The same learner-facing diagnostic applies to compatibility functions written with `TAKES` / `LEARNED`, so older lessons do not get a less-helpful error when a return expression is still unknown. + Known NUMBER parameters can also be used in arithmetic return expressions. Numeric division is accepted when both operands are known numbers: ```claro diff --git a/docs/CURRENT_STATUS.md b/docs/CURRENT_STATUS.md index 2f0a3b8..a7d5185 100644 --- a/docs/CURRENT_STATUS.md +++ b/docs/CURRENT_STATUS.md @@ -58,6 +58,7 @@ Ready now: - `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 +- typed function return diagnostics also identify an unknown return expression in compatibility `TAKES` / `LEARNED` functions, matching the modern function and object-method guidance - `TYPE OF` reports a direct repair hint when the learner forgets `AS`, for example `TYPE OF score` suggests `TYPE OF score AS kind` - `TYPE OF` rejects extra words after its result name with a direct repair hint, so `TYPE OF score AS kind extra` explains that only one result name belongs there; typed `TEACH ... RETURNS TYPE` declarations likewise reject extra words after the return type with a direct repair hint - typed `TEACH ... RETURNS` declarations reject a missing return type with a direct repair hint, such as `Function greet needs a return type after RETURNS. Add a type such as NUMBER.` The same diagnostic names the complete class and method, including compatibility `TAKES` / `LEARNED` methods: `Method Player.score needs a return type after RETURNS. Add a type such as NUMBER.` diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 37d2d3b..7eeeb25 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -86,6 +86,7 @@ Keep declared return types honest: `claro typecheck` now reports friendly diagno 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 functions and object methods now have focused fixtures for `RETURN value extra`, so errors keep the function or class-and-method name and the same repair hint. 8q.12. Keep empty typed-return diagnostics aligned across syntax generations: modern and compatibility functions and object methods now have focused fixtures for bare `RETURN`, so each form explains that the declared type needs an expression. +8q.13. Keep unknown typed-return diagnostics aligned across syntax generations: compatibility `TAKES` / `LEARNED` functions now have a focused fixture for an uninferable return expression, matching modern functions and methods. ### 1. Strong static types diff --git a/tests/test_validate_typecheck_diagnostics.py b/tests/test_validate_typecheck_diagnostics.py index 69643a1..a1b423f 100644 --- a/tests/test_validate_typecheck_diagnostics.py +++ b/tests/test_validate_typecheck_diagnostics.py @@ -71,6 +71,12 @@ class ValidateTypecheckDiagnosticsTests(unittest.TestCase): MODULE.EXPECTED_OK, ) + def test_includes_unknown_compatibility_function_return_expression_fixture(self): + self.assertIn( + "tests/typecheck_function_compat_unknown_return_expression_bad.claro", + MODULE.EXPECTED, + ) + def test_includes_missing_object_name_fixture(self): self.assertIn( "tests/typecheck_missing_object_name_bad.claro", diff --git a/tests/typecheck_function_compat_unknown_return_expression_bad.claro b/tests/typecheck_function_compat_unknown_return_expression_bad.claro new file mode 100644 index 0000000..fa8d683 --- /dev/null +++ b/tests/typecheck_function_compat_unknown_return_expression_bad.claro @@ -0,0 +1,4 @@ +TEACH square TAKES amount RETURNS NUMBER + CHECK TYPE amount IS NUMBER + RETURN missing +LEARNED diff --git a/tools/validate_typecheck_diagnostics.py b/tools/validate_typecheck_diagnostics.py index 87468b3..0e174a4 100644 --- a/tools/validate_typecheck_diagnostics.py +++ b/tools/validate_typecheck_diagnostics.py @@ -130,6 +130,9 @@ EXPECTED = { "tests/typecheck_function_unknown_return_expression_bad.claro": [ "tests/typecheck_function_unknown_return_expression_bad.claro:2: Function square's return value could not be understood yet. Use a NUMBER expression after RETURN.", ], + "tests/typecheck_function_compat_unknown_return_expression_bad.claro": [ + "tests/typecheck_function_compat_unknown_return_expression_bad.claro:3: Function square's return value could not be understood yet. Use a NUMBER expression after RETURN.", + ], "tests/typecheck_function_missing_return_bad.claro": [ "tests/typecheck_function_missing_return_bad.claro:3: Function square declares RETURNS NUMBER but has no RETURN statement. Add RETURN with a NUMBER value.", ],