test: cover extra return tokens in methods

This commit is contained in:
Hermes Agent
2026-09-18 19:33:51 +00:00
parent ebfa3aa52e
commit ea15117a1f
6 changed files with 22 additions and 1 deletions
+2
View File
@@ -284,6 +284,8 @@ END
Function square has extra text after return value amount. Keep only one expression after RETURN. 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: If a function or method declares `RETURNS TYPE` but contains no `RETURN`, the checker points out the missing statement:
```text ```text
+1 -1
View File
@@ -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 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` 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.` - `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` 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
+1
View File
@@ -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.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.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.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 ### 1. Strong static types
@@ -0,0 +1,6 @@
CLASS Player
HAS score NUMBER
TEACH total TAKES amount RETURNS NUMBER
RETURN amount extra
LEARNED
END
@@ -0,0 +1,6 @@
CLASS Player
HAS score NUMBER
TEACH total RETURNS NUMBER
RETURN 1 extra
END
END
+6
View File
@@ -70,6 +70,12 @@ EXPECTED = {
"tests/typecheck_function_return_extra_tokens_bad.claro": [ "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_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": [
"tests/typecheck_function_lowercase_return_bad.claro:2: Type mismatch for return from square: expected NUMBER, but this value looks like TEXT.", "tests/typecheck_function_lowercase_return_bad.claro:2: Type mismatch for return from square: expected NUMBER, but this value looks like TEXT.",
], ],