test: cover compatibility complete branch returns
This commit is contained in:
@@ -102,6 +102,20 @@ Function choose declares RETURNS NUMBER but does not return a NUMBER value on ev
|
|||||||
|
|
||||||
Use `ELSE` with a `RETURN` value, or add a return after the conditional. This compatibility example is part of the focused release validation matrix.
|
Use `ELSE` with a `RETURN` value, or add a return after the conditional. This compatibility example is part of the focused release validation matrix.
|
||||||
|
|
||||||
|
A complete compatibility conditional is accepted when both branches return the declared type:
|
||||||
|
|
||||||
|
```claro
|
||||||
|
TEACH choose TAKES flag RETURNS NUMBER
|
||||||
|
IF flag
|
||||||
|
RETURN 1
|
||||||
|
ELSE
|
||||||
|
RETURN 2
|
||||||
|
END
|
||||||
|
LEARNED
|
||||||
|
```
|
||||||
|
|
||||||
|
This positive `TAKES` / `LEARNED` example is checked by both the focused typecheck validator and `claro validate`.
|
||||||
|
|
||||||
## Complete conditional returns
|
## Complete conditional returns
|
||||||
|
|
||||||
### Return expressions that need more information
|
### Return expressions that need more information
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ Ready now:
|
|||||||
- 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
|
||||||
- compatibility `TAKES` / `LEARNED` functions also have focused positive numeric-addition, subtraction, division, and multiplication return fixtures, keeping arithmetic return coverage aligned with modern functions and compatibility methods.
|
- compatibility `TAKES` / `LEARNED` functions also have focused positive numeric-addition, subtraction, division, and multiplication return fixtures, keeping arithmetic return coverage aligned with modern functions and compatibility methods.
|
||||||
|
- compatibility `TAKES` / `LEARNED` functions have positive complete-branch return coverage beside the incomplete-branch diagnostic, so older conditional examples are checked for both accepted and rejected paths.
|
||||||
- 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 ... 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 ...` 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 ... 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 ...` 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
|
||||||
- simple function and object-method return checks with `TEACH name ... RETURNS TYPE` now include a compatibility `TAKES` / `LEARNED` function whose conditional returns are incomplete, preserving the same every-path diagnostic as modern functions.
|
- simple function and object-method return checks with `TEACH name ... RETURNS TYPE` now include a compatibility `TAKES` / `LEARNED` function whose conditional returns are incomplete, preserving the same every-path diagnostic as modern functions.
|
||||||
- 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
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
@@ -117,6 +117,12 @@ class ValidateTypecheckDiagnosticsTests(unittest.TestCase):
|
|||||||
MODULE.EXPECTED,
|
MODULE.EXPECTED,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_includes_compatibility_branch_complete_function_return_fixture(self):
|
||||||
|
self.assertIn(
|
||||||
|
"tests/typecheck_function_compat_branch_complete_good.claro",
|
||||||
|
MODULE.EXPECTED_OK,
|
||||||
|
)
|
||||||
|
|
||||||
def test_includes_empty_function_return_fixture(self):
|
def test_includes_empty_function_return_fixture(self):
|
||||||
self.assertIn("tests/typecheck_function_empty_return_bad.claro", MODULE.EXPECTED)
|
self.assertIn("tests/typecheck_function_empty_return_bad.claro", MODULE.EXPECTED)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
TEACH choose TAKES flag RETURNS NUMBER
|
||||||
|
IF flag
|
||||||
|
RETURN 1
|
||||||
|
ELSE
|
||||||
|
RETURN 2
|
||||||
|
END
|
||||||
|
LEARNED
|
||||||
|
|
||||||
|
CALL choose WITH YES
|
||||||
@@ -486,6 +486,7 @@ EXPECTED_OK = [
|
|||||||
"tests/typecheck_function_unknown_return_expression_good.claro",
|
"tests/typecheck_function_unknown_return_expression_good.claro",
|
||||||
"tests/typecheck_function_branch_complete_good.claro",
|
"tests/typecheck_function_branch_complete_good.claro",
|
||||||
"tests/typecheck_function_nested_branch_complete_good.claro",
|
"tests/typecheck_function_nested_branch_complete_good.claro",
|
||||||
|
"tests/typecheck_function_compat_branch_complete_good.claro",
|
||||||
"tests/typecheck_method_return_good.claro",
|
"tests/typecheck_method_return_good.claro",
|
||||||
"tests/typecheck_method_field_return_good.claro",
|
"tests/typecheck_method_field_return_good.claro",
|
||||||
"tests/typecheck_method_compat_field_return_good.claro",
|
"tests/typecheck_method_compat_field_return_good.claro",
|
||||||
|
|||||||
Reference in New Issue
Block a user