test: cover unknown compatibility return expressions

This commit is contained in:
Hermes Agent
2026-09-19 01:43:51 +00:00
parent b79db4f25c
commit 039da8159e
6 changed files with 17 additions and 0 deletions
+2
View File
@@ -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. 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: Known NUMBER parameters can also be used in arithmetic return expressions. Numeric division is accepted when both operands are known numbers:
```claro ```claro
+1
View File
@@ -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` 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 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 - `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` 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 - `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.` - 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.`
+1
View File
@@ -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.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.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.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 ### 1. Strong static types
@@ -71,6 +71,12 @@ class ValidateTypecheckDiagnosticsTests(unittest.TestCase):
MODULE.EXPECTED_OK, 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): def test_includes_missing_object_name_fixture(self):
self.assertIn( self.assertIn(
"tests/typecheck_missing_object_name_bad.claro", "tests/typecheck_missing_object_name_bad.claro",
@@ -0,0 +1,4 @@
TEACH square TAKES amount RETURNS NUMBER
CHECK TYPE amount IS NUMBER
RETURN missing
LEARNED
+3
View File
@@ -130,6 +130,9 @@ EXPECTED = {
"tests/typecheck_function_unknown_return_expression_bad.claro": [ "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_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": [
"tests/typecheck_function_missing_return_bad.claro:3: Function square declares RETURNS NUMBER but has no RETURN statement. Add RETURN with a NUMBER value.", "tests/typecheck_function_missing_return_bad.claro:3: Function square declares RETURNS NUMBER but has no RETURN statement. Add RETURN with a NUMBER value.",
], ],