typecheck: explain text division operands
This commit is contained in:
@@ -236,6 +236,7 @@ The checker also identifies text operands in other arithmetic expressions. For e
|
|||||||
```text
|
```text
|
||||||
Type mismatch for field player.score: subtraction needs NUMBER values, but player.name looks like TEXT.
|
Type mismatch for field player.score: subtraction needs NUMBER values, but player.name looks like TEXT.
|
||||||
Type mismatch for field player.score: multiplication needs NUMBER values, but player.name looks like TEXT.
|
Type mismatch for field player.score: multiplication needs NUMBER values, but player.name looks like TEXT.
|
||||||
|
Type mismatch for field player.score: division needs NUMBER values, but player.name looks like TEXT.
|
||||||
```
|
```
|
||||||
|
|
||||||
TEXT-valued and YESNO-valued field-name mistakes are validated too:
|
TEXT-valued and YESNO-valued field-name mistakes are validated too:
|
||||||
|
|||||||
@@ -89,14 +89,14 @@ Type mismatch for field backup.score: expected NUMBER, but this value looks like
|
|||||||
|
|
||||||
This remains limited to direct assignments through simple alias chains; control-flow and complex object-flow analysis are still planned.
|
This remains limited to direct assignments through simple alias chains; control-flow and complex object-flow analysis are still planned.
|
||||||
|
|
||||||
Text operands are also identified when they appear in subtraction, multiplication, or division expressions. This catches a common beginner mistake such as subtracting a text field from a number field:
|
Text operands are also identified when they appear in subtraction, multiplication, or division expressions. The diagnostic names the operator and the text operand, which catches a common beginner mistake such as subtracting a text field from a number field:
|
||||||
|
|
||||||
```claro
|
```claro
|
||||||
SET player.score player.score - player.name
|
SET player.score player.score - player.name
|
||||||
```
|
```
|
||||||
|
|
||||||
```text
|
```text
|
||||||
Type mismatch for field player.score: expected NUMBER, but this value looks like TEXT.
|
Type mismatch for field player.score: subtraction needs NUMBER values, but player.name looks like TEXT.
|
||||||
```
|
```
|
||||||
|
|
||||||
The same learner-facing result is preserved for multiplication, so the checker does not lose the useful `TEXT` type when the invalid expression uses `*`:
|
The same learner-facing result is preserved for multiplication, so the checker does not lose the useful `TEXT` type when the invalid expression uses `*`:
|
||||||
@@ -106,7 +106,7 @@ SET player.score player.score * player.name
|
|||||||
```
|
```
|
||||||
|
|
||||||
```text
|
```text
|
||||||
Type mismatch for field player.score: expected NUMBER, but this value looks like TEXT.
|
Type mismatch for field player.score: multiplication needs NUMBER values, but player.name looks like TEXT.
|
||||||
```
|
```
|
||||||
|
|
||||||
Division is covered in the same way:
|
Division is covered in the same way:
|
||||||
@@ -116,7 +116,7 @@ SET player.score player.score / player.name
|
|||||||
```
|
```
|
||||||
|
|
||||||
```text
|
```text
|
||||||
Type mismatch for field player.score: expected NUMBER, but this value looks like TEXT.
|
Type mismatch for field player.score: division needs NUMBER values, but player.name looks like TEXT.
|
||||||
```
|
```
|
||||||
|
|
||||||
Numeric division remains accepted in a NUMBER field, so the type checker protects both sides of this operator without rejecting a valid beginner expression:
|
Numeric division remains accepted in a NUMBER field, so the type checker protects both sides of this operator without rejecting a valid beginner expression:
|
||||||
@@ -136,7 +136,7 @@ SET player.score player.score * 2
|
|||||||
|
|
||||||
The focused validation matrix keeps this valid arithmetic case beside the multiplication text-operand diagnostic, so a useful expression is not confused with the nearby beginner mistake.
|
The focused validation matrix keeps this valid arithmetic case beside the multiplication text-operand diagnostic, so a useful expression is not confused with the nearby beginner mistake.
|
||||||
|
|
||||||
The expression checker still deliberately reports only the type it can infer; full operator-specific rules remain future work.
|
The expression checker now gives operator-specific guidance for known TEXT operands in subtraction, multiplication, and division. Broader expression inference remains future work.
|
||||||
|
|
||||||
`CHECK TYPE` also preserves TEXT field metadata through the same chained aliases:
|
`CHECK TYPE` also preserves TEXT field metadata through the same chained aliases:
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ Ready now:
|
|||||||
|
|
||||||
Still needed:
|
Still needed:
|
||||||
- Keep the focused typecheck validator's fixture list complete as new positive and negative examples are added.
|
- Keep the focused typecheck validator's fixture list complete as new positive and negative examples are added.
|
||||||
- The expression checker now carries a known TEXT operand through all arithmetic operators so object-field diagnostics do not hide subtraction, multiplication, or division mistakes; focused numeric-division and numeric-multiplication positives plus text-operand subtraction, multiplication, and division negatives protect this behavior. Subtraction and multiplication now name the text operand and explain that the operator needs NUMBER values; division-specific guidance remains planned.
|
- The expression checker now carries a known TEXT operand through all arithmetic operators so object-field diagnostics do not hide subtraction, multiplication, or division mistakes; focused numeric-division and numeric-multiplication positives plus text-operand subtraction, multiplication, and division negatives protect this behavior. Subtraction, multiplication, and division name the text operand and explain that the operator needs NUMBER values.
|
||||||
- richer typed function signatures and return values
|
- richer typed function signatures and return values
|
||||||
- type checking through branches and loops
|
- type checking through branches and loops
|
||||||
- richer object field type checking beyond simple direct assignments
|
- richer object field type checking beyond simple direct assignments
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@ See `CURRENT_STATUS.md` for the detailed feature matrix.
|
|||||||
3b. Keep package security validation in Forgejo/Gitea CI so unsafe names, exact manifest-version/name/version/checksum mismatches, missing manifests, duplicate project manifest versions and packages, duplicate lock packages, duplicate package manifest names, versions, and checksums, and lockfile errors remain release blockers.
|
3b. Keep package security validation in Forgejo/Gitea CI so unsafe names, exact manifest-version/name/version/checksum mismatches, missing manifests, duplicate project manifest versions and packages, duplicate lock packages, duplicate package manifest names, versions, and checksums, and lockfile errors remain release blockers.
|
||||||
4. Add small examples for each foundation feature before adding bigger syntax. The object-field foundation now includes positive and negative validation for field expressions such as `SET player.score player.name`, `SET player.score player.score + 1`, `SET player.name player.score + 1`, explicitly typed field assignments, simple and chained aliases such as `SET alias player`, `SET backup alias`, followed by `SET backup.score ...` or `CHECK TYPE backup.score IS ...`, chained aliases in object-method calls through both modern `DO` and compatibility `CALL ... WITH` forms (including a dedicated positive modern `DO` fixture), and arithmetic/text expression mismatches; typed containers also accept a map with nested type metadata when it is added to a `LIST OF MAP`; broader alias/control-flow checking remains planned.
|
4. Add small examples for each foundation feature before adding bigger syntax. The object-field foundation now includes positive and negative validation for field expressions such as `SET player.score player.name`, `SET player.score player.score + 1`, `SET player.name player.score + 1`, explicitly typed field assignments, simple and chained aliases such as `SET alias player`, `SET backup alias`, followed by `SET backup.score ...` or `CHECK TYPE backup.score IS ...`, chained aliases in object-method calls through both modern `DO` and compatibility `CALL ... WITH` forms (including a dedicated positive modern `DO` fixture), and arithmetic/text expression mismatches; typed containers also accept a map with nested type metadata when it is added to a `LIST OF MAP`; broader alias/control-flow checking remains planned.
|
||||||
5. Keep the focused typecheck validator complete: every `typecheck_*.claro` fixture, including positive fixtures, must be exercised by release validation.
|
5. Keep the focused typecheck validator complete: every `typecheck_*.claro` fixture, including positive fixtures, must be exercised by release validation.
|
||||||
6. Continue narrowing expression diagnostics: known TEXT operands now remain visible through non-concatenation arithmetic, with focused numeric-division and numeric-multiplication positives plus text-operand subtraction, multiplication, and division coverage. Subtraction and multiplication now give operator-specific guidance naming the text operand; matching division guidance remains future work.
|
6. Continue narrowing expression diagnostics: known TEXT operands now remain visible through non-concatenation arithmetic, with focused numeric-division and numeric-multiplication positives plus text-operand subtraction, multiplication, and division coverage. Subtraction, multiplication, and division give operator-specific guidance naming the text operand.
|
||||||
|
|
||||||
## Complete-platform milestones
|
## Complete-platform milestones
|
||||||
|
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
@@ -117,7 +117,7 @@ EXPECTED = {
|
|||||||
"tests/typecheck_object_field_multiplication_bad.claro:8: Type mismatch for field player.score: multiplication needs NUMBER values, but player.name looks like TEXT.",
|
"tests/typecheck_object_field_multiplication_bad.claro:8: Type mismatch for field player.score: multiplication needs NUMBER values, but player.name looks like TEXT.",
|
||||||
],
|
],
|
||||||
"tests/typecheck_object_field_division_bad.claro": [
|
"tests/typecheck_object_field_division_bad.claro": [
|
||||||
"tests/typecheck_object_field_division_bad.claro:8: Type mismatch for field player.score: expected NUMBER, but this value looks like TEXT.",
|
"tests/typecheck_object_field_division_bad.claro:8: Type mismatch for field player.score: division needs NUMBER values, but player.name looks like TEXT.",
|
||||||
],
|
],
|
||||||
"tests/typecheck_object_field_text_expression_bad.claro": [
|
"tests/typecheck_object_field_text_expression_bad.claro": [
|
||||||
"tests/typecheck_object_field_text_expression_bad.claro:8: Type mismatch for field player.name: expected TEXT, but this value looks like NUMBER.",
|
"tests/typecheck_object_field_text_expression_bad.claro:8: Type mismatch for field player.name: expected TEXT, but this value looks like NUMBER.",
|
||||||
|
|||||||
Reference in New Issue
Block a user