typecheck: validate object method returns

This commit is contained in:
Hermes Agent
2026-09-08 21:36:00 +00:00
parent 8fe57974c6
commit 9d4cffa6f6
8 changed files with 53 additions and 9 deletions
+2 -2
View File
@@ -162,7 +162,7 @@ Function square only accepts 1 argument, but this call gives 2. Remove the extra
Function squre is not known yet. Check the function name or add TEACH squre before calling it.
```
Simple functions can also declare a return type. `claro typecheck` checks each `RETURN` expression against it:
Simple functions and object methods can also declare a return type. `claro typecheck` checks each `RETURN` expression against it:
```claro
TEACH square amount RETURNS NUMBER
@@ -171,7 +171,7 @@ TEACH square amount RETURNS NUMBER
END
```
Returning text from this function reports: `Type mismatch for return from square: expected NUMBER, but this value looks like TEXT.`
The same focused check applies to methods such as `Player.score RETURNS NUMBER`; a wrong return reports the full method name, for example: `Type mismatch for return from Player.score: expected NUMBER, but this value looks like TEXT.`
The unknown-function diagnostic is validated for both modern `DO squre 4` and compatibility `CALL squre WITH 4` calls. Compatibility calls that leave `WITH` empty, such as `CALL greet WITH`, now count as zero arguments, so learners get the same missing-argument guidance as `DO greet` instead of the checker treating the blank as an argument.