feat: improve object field type diagnostics
This commit is contained in:
@@ -125,6 +125,33 @@ Type mismatch for method Player.add: parameter points needs NUMBER, but this arg
|
||||
|
||||
Both sides of this narrow method foundation are covered by validation: `tests/typecheck_method_good.claro` checks that `DO player.add 5` is accepted, and `tests/typecheck_method_bad.claro` checks the friendly wrong-type diagnostic.
|
||||
|
||||
## Object field assignment checks
|
||||
|
||||
Claro also has a narrow static diagnostic for direct object-field assignments. If a class declares a typed field and a script creates a simple object with `NEW Class name`, `claro typecheck` remembers the field type:
|
||||
|
||||
```claro
|
||||
CLASS Player
|
||||
HAS score NUMBER
|
||||
END
|
||||
|
||||
NEW Player player
|
||||
SET player.score 10
|
||||
```
|
||||
|
||||
If a learner assigns the wrong value type directly to that known field:
|
||||
|
||||
```claro
|
||||
SET player.score "ten"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```text
|
||||
Type mismatch for field player.score: expected NUMBER, but this value looks like TEXT.
|
||||
```
|
||||
|
||||
This slice is intentionally small: it covers direct `NEW Class object` plus `SET object.field value` cases in one file. Broader object flows, aliases, method return checks, and richer object signatures remain future work.
|
||||
|
||||
## Status
|
||||
|
||||
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.
|
||||
This is currently a static checker feature. It improves `claro typecheck` and validation confidence for `DO` and compatibility `CALL ... WITH` function calls, simple `DO object.method ...` calls where the object was created with `NEW Class name`, and direct assignments to known object fields. Runtime enforcement for every container mutation and richer function/object signatures can be added later after the syntax is classroom-tested.
|
||||
|
||||
@@ -53,11 +53,12 @@ Ready now:
|
||||
- `TYPE OF` and `CHECK TYPE`
|
||||
- typed list/map checks through `claro typecheck`
|
||||
- a narrow function/method argument check: `CHECK TYPE parameter IS TYPE` inside a function or simple object method lets `claro typecheck` accept correct checked calls and catch mismatched `DO`, `CALL ... WITH`, and `DO object.method ...` arguments
|
||||
- a narrow object-field assignment check for simple `NEW Class object` plus direct `SET object.field value` cases when the class declares `HAS field TYPE`
|
||||
|
||||
Still needed:
|
||||
- richer typed function signatures and return values
|
||||
- type checking through branches and loops
|
||||
- richer object field type checking
|
||||
- richer object field type checking beyond simple direct assignments
|
||||
- typed imports/modules
|
||||
|
||||
Good starting docs:
|
||||
@@ -74,10 +75,11 @@ Ready now:
|
||||
- `NEW`
|
||||
- field access such as `player.score`
|
||||
- simple methods, including static diagnostics for checked method parameters
|
||||
- direct object-field assignments with a narrow static diagnostic for wrong value types
|
||||
- object helper commands
|
||||
|
||||
Still needed:
|
||||
- stronger object field type checking
|
||||
- broader object field type checking across aliases, methods, and more complex object flows
|
||||
- constructor/default-value polish
|
||||
- clearer object debugging and teaching examples
|
||||
|
||||
|
||||
+2
-2
@@ -31,7 +31,7 @@ See `CURRENT_STATUS.md` for the detailed feature matrix.
|
||||
|
||||
1. Keep beginner-facing docs current and separate from historical release notes.
|
||||
2. Keep examples aligned with the modern simple syntax (`END`, `DO`, short `SET`, short `ASK`) while documenting older compatibility forms separately.
|
||||
3. Expand validation around typecheck diagnostics and package/networking safety. Current object-method parameter validation covers one correct `DO object.method ...` call and one wrong-type diagnostic.
|
||||
3. Expand validation around typecheck diagnostics and package/networking safety. Current object-method parameter validation covers one correct `DO object.method ...` call and one wrong-type diagnostic; object-field validation also covers one simple wrong-type direct assignment after `NEW Class object`.
|
||||
4. Add small examples for each foundation feature before adding bigger syntax.
|
||||
|
||||
## Complete-platform milestones
|
||||
@@ -45,7 +45,7 @@ Needed next:
|
||||
- typed function returns
|
||||
- type checking across branches and loops
|
||||
- typed imports/modules
|
||||
- richer object field checking and method return typing
|
||||
- broader object field checking and method return typing
|
||||
- clearer error messages for type mismatches
|
||||
|
||||
### 2. Objects and classes polish
|
||||
|
||||
Reference in New Issue
Block a user