test: cover unknown method return expressions

This commit is contained in:
Hermes Agent
2026-09-11 05:25:39 +00:00
parent 34f96a6d7d
commit c82d67a34a
7 changed files with 44 additions and 3 deletions
+16 -1
View File
@@ -396,6 +396,21 @@ Returning text from this method produces a learner-facing diagnostic that names
Type mismatch for return from Player.score: expected NUMBER, but this value looks like TEXT.
```
If a method's return expression is not understood yet, the diagnostic names the method and gives the promised type so the learner knows what to replace:
```claro
CLASS Player
TEACH square amount RETURNS NUMBER
CHECK TYPE amount IS NUMBER
RETURN missing
END
END
```
```text
Method Player.square's return value could not be understood yet. Use a NUMBER expression after RETURN.
```
Methods can also return a typed field declared by their class. A field is available by its simple name inside the method, so `RETURN score` is checked against `HAS score NUMBER` instead of being treated as an unknown expression. Returning that field from a method declared `RETURNS TEXT` reports the same expected-versus-found diagnostic.
This is a focused check for simple return expressions. When a parameter has a `CHECK TYPE` declaration, that known type also informs arithmetic return expressions in functions and methods, so `RETURN amount + 1` is checked against the declared return type. The `RETURNS` keyword is case-insensitive in both modern and compatibility function forms, so `returns NUMBER` keeps working while learners are still getting used to Claro's capitalization. A declared return with no `RETURN`, or with a `RETURN` only inside an `IF`, gets a beginner-facing message explaining that the function may finish without returning the promised type:
@@ -404,7 +419,7 @@ This is a focused check for simple return expressions. When a parameter has a `C
Function choose declares RETURNS NUMBER but does not return a NUMBER value on every path. Add RETURN to each branch or after the conditional.
```
The focused validation matrix covers modern and compatibility syntax, method success and mismatch fixtures, typed field returns, missing returns, and conditional-only returns. It also includes a positive nested `IF`/`ELSE` return example inside a method, so a complete nested method path is protected from regression. Full path-sensitive analysis proving that every `IF`/`ELSE` branch returns remains planned.
The focused validation matrix covers modern and compatibility syntax, method success and mismatch fixtures, unknown method return expressions, typed field returns, missing returns, and conditional-only returns. It also includes a positive nested `IF`/`ELSE` return example inside a method, so a complete nested method path is protected from regression. Full path-sensitive analysis proving that every `IF`/`ELSE` branch returns remains planned.
## Object method parameter checks