test: cover compatibility function return tokens
This commit is contained in:
@@ -286,6 +286,8 @@ Function square has extra text after return value amount. Keep only one expressi
|
|||||||
|
|
||||||
The same focused repair applies to modern and compatibility object methods, and names the complete method such as `Player.total`.
|
The same focused repair applies to modern and compatibility object methods, and names the complete method such as `Player.total`.
|
||||||
|
|
||||||
|
Compatibility functions using `TAKES` / `LEARNED` receive the same repair when a return value has extra text. For example, `RETURN amount extra` reports `Function square has extra text after return value amount. Keep only one expression after RETURN.`
|
||||||
|
|
||||||
If a function or method declares `RETURNS TYPE` but contains no `RETURN`, the checker points out the missing statement:
|
If a function or method declares `RETURNS TYPE` but contains no `RETURN`, the checker points out the missing statement:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ Ready now:
|
|||||||
- `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
|
- `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 `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
|
- typed list/map checks through `claro typecheck`, including a nested `LIST OF MAP` insertion example
|
||||||
- simple function and object-method return checks with `TEACH name ... RETURNS TYPE`, including learner-facing diagnostics for unknown declared return types, mismatched or not-yet-inferable `RETURN` expressions (including method-specific diagnostics naming the class and method, with modern and compatibility method coverage), empty `RETURN` statements in modern and compatibility methods, declarations that contain no `RETURN`, and declarations whose only return is inside an incomplete conditional; missing return types are checked for modern functions and both modern and compatibility methods, with compatibility-function coverage as well; `RETURNS` is case-insensitive like other Claro keywords and has positive coverage in both modern and compatibility function forms, including lowercase compatibility declarations and lowercase compatibility method declarations, plus a lowercase compatibility-method mismatch diagnostic; positive function-return coverage includes numeric multiplication; compatibility methods now have dedicated positive numeric addition, subtraction, division, and multiplication return fixtures plus compatibility addition, subtraction, division, and multiplication diagnostic fixtures; NUMBER return diagnostics name a known TEXT operand and arithmetic operation instead of hiding the cause behind a generic mismatch, with focused addition, subtraction, multiplication, and division coverage for functions and methods; typed-function return diagnostics now have focused subtraction and division positives alongside multiplication coverage. Text concatenation into a TEXT field has focused positive fixtures for both operand orders, including concatenation of two TEXT object fields. Each numeric operator names the text operand and explains that it needs NUMBER values.
|
- simple function and object-method return checks with `TEACH name ... RETURNS TYPE`, including learner-facing diagnostics for unknown declared return types, mismatched or not-yet-inferable `RETURN` expressions (including method-specific diagnostics naming the class and method, with modern and compatibility method coverage), empty `RETURN` statements in modern and compatibility methods, declarations that contain no `RETURN`, and declarations whose only return is inside an incomplete conditional; missing return types are checked for modern functions and both modern and compatibility methods, with compatibility-function coverage as well; extra text after a return value is rejected consistently in modern functions, compatibility `TAKES` / `LEARNED` functions, and both method forms; `RETURNS` is case-insensitive like other Claro keywords and has positive coverage in both modern and compatibility function forms, including lowercase compatibility declarations and lowercase compatibility method declarations, plus a lowercase compatibility-method mismatch diagnostic; positive function-return coverage includes numeric multiplication; compatibility methods now have dedicated positive numeric addition, subtraction, division, and multiplication return fixtures plus compatibility addition, subtraction, division, and multiplication diagnostic fixtures; NUMBER return diagnostics name a known TEXT operand and arithmetic operation instead of hiding the cause behind a generic mismatch, with focused addition, subtraction, multiplication, and division coverage for functions and methods; typed-function return diagnostics now have focused subtraction and division positives alongside multiplication coverage. Text concatenation into a TEXT field has focused positive fixtures for both operand orders, including concatenation of two TEXT object fields. Each numeric operator names the text operand and explains that it needs NUMBER values.
|
||||||
- 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, catch mismatched `DO`, `CALL ... WITH`, `DO object.method ...`, and compatibility `CALL object.method WITH ...` arguments, including checked methods that appear after another method in the same class, report missing checked function and method arguments, report missing unchecked arguments for simple functions and simple object methods in both modern `DO` and compatibility `CALL ... WITH` forms, treat empty compatibility calls such as `CALL greet WITH` and `CALL player.rename WITH` as missing-argument mistakes, catch extra arguments to simple functions and checked methods even when the checked method appears after another method in the same class, catch modern `DO` and compatibility `CALL ... WITH` calls to undeclared simple functions, explain when `DO object.method ...` or compatibility `CALL object.method ...` happens before the object is created with `NEW` even if the method name is also wrong, and catch modern plus compatibility calls to undeclared object methods with a class-specific `TEACH` hint
|
- 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, catch mismatched `DO`, `CALL ... WITH`, `DO object.method ...`, and compatibility `CALL object.method WITH ...` arguments, including checked methods that appear after another method in the same class, report missing checked function and method arguments, report missing unchecked arguments for simple functions and simple object methods in both modern `DO` and compatibility `CALL ... WITH` forms, treat empty compatibility calls such as `CALL greet WITH` and `CALL player.rename WITH` as missing-argument mistakes, catch extra arguments to simple functions and checked methods even when the checked method appears after another method in the same class, catch modern `DO` and compatibility `CALL ... WITH` calls to undeclared simple functions, explain when `DO object.method ...` or compatibility `CALL object.method ...` happens before the object is created with `NEW` even if the method name is also wrong, and catch modern plus compatibility calls to undeclared object methods with a class-specific `TEACH` hint
|
||||||
- function and method declarations now reject repeated parameter names with a direct repair hint before calls are checked, including modern and compatibility `TAKES` / `LEARNED` functions and methods; object methods with the same name are also rejected within a class with a rename hint in both modern and compatibility method syntax
|
- function and method declarations now reject repeated parameter names with a direct repair hint before calls are checked, including modern and compatibility `TAKES` / `LEARNED` functions and methods; object methods with the same name are also rejected within a class with a rename hint in both modern and compatibility method syntax
|
||||||
- top-level function declarations now reject repeated names with a direct repair hint, so two `TEACH greet` blocks cannot silently compete for one callable function; a missing function name after `TEACH` gets a direct beginner-facing repair hint, and a missing method name inside `CLASS` names the class and gives a method example
|
- top-level function declarations now reject repeated names with a direct repair hint, so two `TEACH greet` blocks cannot silently compete for one callable function; a missing function name after `TEACH` gets a direct beginner-facing repair hint, and a missing method name inside `CLASS` names the class and gives a method example
|
||||||
|
|||||||
+1
-1
@@ -84,7 +84,7 @@ Keep declared return types honest: `claro typecheck` now reports friendly diagno
|
|||||||
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`.
|
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`.
|
||||||
8q.9. Keep missing return-type diagnostics aligned across functions and methods: modern and compatibility methods now name the complete `Class.method` identity when `RETURNS` has no type, with focused fixtures in the typecheck and release validation matrices.
|
8q.9. Keep missing return-type diagnostics aligned across functions and methods: modern and compatibility methods now name the complete `Class.method` identity when `RETURNS` has no type, with focused fixtures in the typecheck and release validation matrices.
|
||||||
8q.10. Keep return statements beginner-readable: typed returns now identify simple extra tokens after a value and explain that `RETURN` accepts one expression, with focused release validation coverage.
|
8q.10. Keep return statements beginner-readable: typed returns now identify simple extra tokens after a value and explain that `RETURN` accepts one expression, with focused release validation coverage.
|
||||||
8q.11. Keep extra-token return diagnostics aligned across syntax generations: modern and compatibility object methods now have focused fixtures for `RETURN value extra`, so method errors keep the class-and-method name and the same repair hint as function errors.
|
8q.11. Keep extra-token return diagnostics aligned across syntax generations: modern and compatibility functions and object methods now have focused fixtures for `RETURN value extra`, so errors keep the function or class-and-method name and the same repair hint.
|
||||||
|
|
||||||
### 1. Strong static types
|
### 1. Strong static types
|
||||||
|
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
@@ -114,6 +114,12 @@ class ValidateTypecheckDiagnosticsTests(unittest.TestCase):
|
|||||||
MODULE.EXPECTED,
|
MODULE.EXPECTED,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_includes_compatibility_function_extra_return_tokens_fixture(self):
|
||||||
|
self.assertIn(
|
||||||
|
"tests/typecheck_function_compat_return_extra_tokens_bad.claro",
|
||||||
|
MODULE.EXPECTED,
|
||||||
|
)
|
||||||
|
|
||||||
def test_includes_empty_compatibility_method_return_fixture(self):
|
def test_includes_empty_compatibility_method_return_fixture(self):
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
"tests/typecheck_method_compat_empty_return_bad.claro",
|
"tests/typecheck_method_compat_empty_return_bad.claro",
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
TEACH square TAKES amount RETURNS NUMBER
|
||||||
|
RETURN amount extra
|
||||||
|
LEARNED
|
||||||
@@ -70,6 +70,9 @@ EXPECTED = {
|
|||||||
"tests/typecheck_function_return_extra_tokens_bad.claro": [
|
"tests/typecheck_function_return_extra_tokens_bad.claro": [
|
||||||
"tests/typecheck_function_return_extra_tokens_bad.claro:2: Function square has extra text after return value amount. Keep only one expression after RETURN.",
|
"tests/typecheck_function_return_extra_tokens_bad.claro:2: Function square has extra text after return value amount. Keep only one expression after RETURN.",
|
||||||
],
|
],
|
||||||
|
"tests/typecheck_function_compat_return_extra_tokens_bad.claro": [
|
||||||
|
"tests/typecheck_function_compat_return_extra_tokens_bad.claro:2: Function square has extra text after return value amount. Keep only one expression after RETURN.",
|
||||||
|
],
|
||||||
"tests/typecheck_method_return_extra_tokens_bad.claro": [
|
"tests/typecheck_method_return_extra_tokens_bad.claro": [
|
||||||
"tests/typecheck_method_return_extra_tokens_bad.claro:4: Method Player.total has extra text after return value 1. Keep only one expression after RETURN.",
|
"tests/typecheck_method_return_extra_tokens_bad.claro:4: Method Player.total has extra text after return value 1. Keep only one expression after RETURN.",
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user