feat: add typed function argument diagnostics
This commit is contained in:
@@ -43,6 +43,36 @@ Output:
|
||||
Type mismatch for map scores: expected NUMBER value, but this value looks like TEXT.
|
||||
```
|
||||
|
||||
## Function parameter checks
|
||||
|
||||
Claro now has a small static-checking foundation for function arguments. Keep the beginner-friendly function syntax, then put the expected type inside the function with `CHECK TYPE`:
|
||||
|
||||
```claro
|
||||
TEACH square amount
|
||||
CHECK TYPE amount IS NUMBER
|
||||
SAY amount
|
||||
END
|
||||
|
||||
DO square 4
|
||||
```
|
||||
|
||||
If a learner calls the function with the wrong kind of value, `claro typecheck` explains which parameter needs which type:
|
||||
|
||||
```claro
|
||||
TEACH square amount
|
||||
CHECK TYPE amount IS NUMBER
|
||||
SAY amount
|
||||
END
|
||||
|
||||
DO square "oops"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```text
|
||||
Type mismatch for function square: parameter amount needs NUMBER, but this argument looks like TEXT.
|
||||
```
|
||||
|
||||
## Status
|
||||
|
||||
This is currently a static checker feature. It improves `claro typecheck` and validation confidence. Runtime enforcement for every container mutation can be added later after the syntax is classroom-tested.
|
||||
This is currently a static checker feature. It improves `claro typecheck` and validation confidence. Runtime enforcement for every container mutation and richer function signatures can be added later after the syntax is classroom-tested.
|
||||
|
||||
@@ -52,9 +52,10 @@ 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 call arguments
|
||||
|
||||
Still needed:
|
||||
- typed function parameters and return values
|
||||
- richer typed function signatures and return values
|
||||
- type checking through branches and loops
|
||||
- object method and field type checking
|
||||
- typed imports/modules
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ See `CURRENT_STATUS.md` for the detailed feature matrix.
|
||||
Goal: make larger beginner programs safer without making first scripts harder.
|
||||
|
||||
Needed next:
|
||||
- typed function parameters
|
||||
- richer typed function signatures
|
||||
- typed function returns
|
||||
- type checking across branches and loops
|
||||
- typed imports/modules
|
||||
|
||||
Reference in New Issue
Block a user