typecheck: diagnose missing TYPE OF expressions
This commit is contained in:
@@ -2,6 +2,20 @@
|
||||
|
||||
Claro v1.18.26 adds the first advanced static-typing foundation: typed containers checked by `claro typecheck`.
|
||||
|
||||
## Complete `TYPE OF` statements
|
||||
|
||||
`TYPE OF` needs an expression, `AS`, and a result name. If the expression is missing, `claro typecheck` gives a repair example instead of silently creating the result variable:
|
||||
|
||||
```claro
|
||||
TYPE OF AS kind
|
||||
```
|
||||
|
||||
```text
|
||||
TYPE OF needs an expression before AS. Try: TYPE OF score AS kind.
|
||||
```
|
||||
|
||||
Add the value whose type should be stored, such as `TYPE OF score AS kind`.
|
||||
|
||||
Class fields need a type after the field name. If a learner writes `HAS score` instead of `HAS score NUMBER`, `claro typecheck` explains the missing piece:
|
||||
|
||||
```text
|
||||
|
||||
@@ -60,6 +60,7 @@ Ready now:
|
||||
- `CHECK TYPE` rejects unknown expected type names with a beginner-facing list of supported types
|
||||
- typed function return diagnostics also identify an unknown return expression in compatibility `TAKES` / `LEARNED` functions, matching the modern function and object-method guidance
|
||||
- `TYPE OF` reports a direct repair hint when the learner forgets `AS`, for example `TYPE OF score` suggests `TYPE OF score AS kind`
|
||||
- `TYPE OF` reports a direct repair hint when the learner forgets the expression before `AS`, for example `TYPE OF AS kind` reports `TYPE OF needs an expression before AS. Try: TYPE OF score AS kind.`
|
||||
- `TYPE OF` rejects extra words after its result name with a direct repair hint, so `TYPE OF score AS kind extra` explains that only one result name belongs there; typed `TEACH ... RETURNS TYPE` declarations likewise reject extra words after the return type with a direct repair hint
|
||||
- typed `TEACH ... RETURNS` declarations reject a missing return type with a direct repair hint, such as `Function greet needs a return type after RETURNS. Add a type such as NUMBER.` The same diagnostic names the complete class and method, including compatibility `TAKES` / `LEARNED` methods: `Method Player.score needs a return type after RETURNS. Add a type such as NUMBER.`
|
||||
- typed list/map checks through `claro typecheck`, including a nested `LIST OF MAP` insertion example
|
||||
|
||||
@@ -79,6 +79,7 @@ Keep declared return types honest: `claro typecheck` now reports friendly diagno
|
||||
8q.3. Keep `CHECK TYPE` declarations complete: a bare `CHECK TYPE` now explains that the expression, `IS`, and expected type are all required, with a complete repair example.
|
||||
8q.4. Keep `CHECK TYPE` declarations ordered: `CHECK TYPE IS NUMBER` now explains that an expression belongs before `IS`, with a complete repair example.
|
||||
8q.5. Keep `TYPE OF` declarations understandable: a missing `AS` now gets a direct repair hint with a complete `TYPE OF score AS kind` example.
|
||||
8q.5.1. Keep `TYPE OF` declarations complete: a missing expression before `AS` now gets a direct repair hint with a complete `TYPE OF score AS kind` example.
|
||||
8q.6. Keep `TYPE OF` declarations unambiguous: extra words after the result name now get a direct repair hint instead of being silently included in the variable name.
|
||||
8q.7. Keep typed `TEACH` declarations unambiguous: extra words after a declared return type now get a direct repair hint instead of being treated as part of an unknown type.
|
||||
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`.
|
||||
|
||||
Reference in New Issue
Block a user