test: cover numeric function return division
This commit is contained in:
@@ -74,6 +74,17 @@ Function square's return value could not be understood yet. Use a NUMBER express
|
|||||||
|
|
||||||
Use a known typed value, such as a parameter checked with `CHECK TYPE`, while broader expression inference remains future work.
|
Use a known typed value, such as a parameter checked with `CHECK TYPE`, while broader expression inference remains future work.
|
||||||
|
|
||||||
|
Known NUMBER parameters can also be used in arithmetic return expressions. Numeric division is accepted when both operands are known numbers:
|
||||||
|
|
||||||
|
```claro
|
||||||
|
TEACH halve amount RETURNS NUMBER
|
||||||
|
CHECK TYPE amount IS NUMBER
|
||||||
|
RETURN amount / 2
|
||||||
|
END
|
||||||
|
```
|
||||||
|
|
||||||
|
This valid division case is included in the focused typecheck validation matrix beside the diagnostic for using a TEXT operand in division.
|
||||||
|
|
||||||
Return declarations accept the same case-insensitive keyword style as the rest of Claro. For example, `returns NUMBER` still enables return checking:
|
Return declarations accept the same case-insensitive keyword style as the rest of Claro. For example, `returns NUMBER` still enables return checking:
|
||||||
|
|
||||||
```claro
|
```claro
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
TEACH halve amount RETURNS NUMBER
|
||||||
|
CHECK TYPE amount IS NUMBER
|
||||||
|
RETURN amount / 2
|
||||||
|
END
|
||||||
|
|
||||||
|
DO halve 8
|
||||||
@@ -261,6 +261,7 @@ EXPECTED_OK = [
|
|||||||
"tests/typecheck_function_lowercase_return_good.claro",
|
"tests/typecheck_function_lowercase_return_good.claro",
|
||||||
"tests/typecheck_function_return_expression_good.claro",
|
"tests/typecheck_function_return_expression_good.claro",
|
||||||
"tests/typecheck_function_return_multiplication_good.claro",
|
"tests/typecheck_function_return_multiplication_good.claro",
|
||||||
|
"tests/typecheck_function_return_division_good.claro",
|
||||||
"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",
|
||||||
|
|||||||
Reference in New Issue
Block a user