feat: add object method parameter diagnostics
This commit is contained in:
@@ -93,6 +93,36 @@ Type mismatch for function label: parameter name needs TEXT, but this argument l
|
||||
Type mismatch for function label: parameter age needs NUMBER, but this argument looks like TEXT.
|
||||
```
|
||||
|
||||
## Object method parameter checks
|
||||
|
||||
Claro also checks simple object method arguments when the method body names a parameter with `CHECK TYPE`. This keeps the method syntax beginner-readable while giving a clearer error before the program runs:
|
||||
|
||||
```claro
|
||||
CLASS Player
|
||||
HAS score NUMBER
|
||||
|
||||
TEACH add points
|
||||
CHECK TYPE points IS NUMBER
|
||||
SET score score + points
|
||||
END
|
||||
END
|
||||
|
||||
NEW Player player
|
||||
DO player.add 5
|
||||
```
|
||||
|
||||
If the learner passes text where the method expects a number:
|
||||
|
||||
```claro
|
||||
DO player.add "five"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```text
|
||||
Type mismatch for method Player.add: parameter points needs NUMBER, but this argument looks like TEXT.
|
||||
```
|
||||
|
||||
## Status
|
||||
|
||||
This is currently a static checker feature. It improves `claro typecheck` and validation confidence for `DO` and compatibility `CALL ... WITH` function calls. Runtime enforcement for every container mutation and richer function signatures can be added later after the syntax is classroom-tested.
|
||||
This is currently a static checker feature. It improves `claro typecheck` and validation confidence for `DO` and compatibility `CALL ... WITH` function calls, plus simple `DO object.method ...` calls where the object was created with `NEW Class name`. Runtime enforcement for every container mutation and richer function/object signatures can be added later after the syntax is classroom-tested.
|
||||
|
||||
@@ -52,12 +52,12 @@ Ready now:
|
||||
- typed variables such as `SET score NUMBER 10`
|
||||
- `TYPE OF` and `CHECK TYPE`
|
||||
- typed list/map checks through `claro typecheck`
|
||||
- a narrow function argument check: `CHECK TYPE parameter IS TYPE` inside a function lets `claro typecheck` catch mismatched `DO` and `CALL ... WITH` arguments, including multiple checked parameters
|
||||
- a narrow function/method argument check: `CHECK TYPE parameter IS TYPE` inside a function or simple object method lets `claro typecheck` catch mismatched `DO`, `CALL ... WITH`, and `DO object.method ...` arguments
|
||||
|
||||
Still needed:
|
||||
- richer typed function signatures and return values
|
||||
- type checking through branches and loops
|
||||
- object method and field type checking
|
||||
- richer object field type checking
|
||||
- typed imports/modules
|
||||
|
||||
Good starting docs:
|
||||
@@ -73,11 +73,11 @@ Ready now:
|
||||
- typed `HAS` fields
|
||||
- `NEW`
|
||||
- field access such as `player.score`
|
||||
- simple methods
|
||||
- simple methods, including static diagnostics for checked method parameters
|
||||
- object helper commands
|
||||
|
||||
Still needed:
|
||||
- stronger method/field type checking
|
||||
- stronger object field type checking
|
||||
- constructor/default-value polish
|
||||
- clearer object debugging and teaching examples
|
||||
|
||||
|
||||
+2
-2
@@ -45,7 +45,7 @@ Needed next:
|
||||
- typed function returns
|
||||
- type checking across branches and loops
|
||||
- typed imports/modules
|
||||
- object field and method type checking
|
||||
- richer object field checking and method return typing
|
||||
- clearer error messages for type mismatches
|
||||
|
||||
### 2. Objects and classes polish
|
||||
@@ -54,7 +54,7 @@ Goal: keep object-oriented examples readable enough for beginners.
|
||||
|
||||
Needed next:
|
||||
- constructor-style defaults or beginner-friendly initialization helpers
|
||||
- method parameter checks
|
||||
- method return checks
|
||||
- object printing/debugging helpers
|
||||
- better examples that avoid abstract toy OOP
|
||||
|
||||
|
||||
Reference in New Issue
Block a user