From 45a323e45bd22222a245d68a988ec1c09cf2b783 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Fri, 11 Sep 2026 23:54:50 +0000 Subject: [PATCH] test: cover numeric function return division --- docs/ADVANCED_STATIC_TYPING.md | 11 +++++++++++ tests/typecheck_function_return_division_good.claro | 6 ++++++ tools/validate_typecheck_diagnostics.py | 1 + 3 files changed, 18 insertions(+) create mode 100644 tests/typecheck_function_return_division_good.claro diff --git a/docs/ADVANCED_STATIC_TYPING.md b/docs/ADVANCED_STATIC_TYPING.md index 90c8dc1..32e53e5 100644 --- a/docs/ADVANCED_STATIC_TYPING.md +++ b/docs/ADVANCED_STATIC_TYPING.md @@ -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. +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: ```claro diff --git a/tests/typecheck_function_return_division_good.claro b/tests/typecheck_function_return_division_good.claro new file mode 100644 index 0000000..f0ac817 --- /dev/null +++ b/tests/typecheck_function_return_division_good.claro @@ -0,0 +1,6 @@ +TEACH halve amount RETURNS NUMBER + CHECK TYPE amount IS NUMBER + RETURN amount / 2 +END + +DO halve 8 diff --git a/tools/validate_typecheck_diagnostics.py b/tools/validate_typecheck_diagnostics.py index 874bada..e486893 100644 --- a/tools/validate_typecheck_diagnostics.py +++ b/tools/validate_typecheck_diagnostics.py @@ -261,6 +261,7 @@ EXPECTED_OK = [ "tests/typecheck_function_lowercase_return_good.claro", "tests/typecheck_function_return_expression_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_branch_complete_good.claro", "tests/typecheck_function_nested_branch_complete_good.claro",