Skip to content

Validate function type annotations at runtime and add signature mismatch tests#369

Open
nbeerbower wants to merge 1 commit into
mainfrom
codex/implement-function-signature-validation
Open

Validate function type annotations at runtime and add signature mismatch tests#369
nbeerbower wants to merge 1 commit into
mainfrom
codex/implement-function-signature-validation

Conversation

@nbeerbower

Copy link
Copy Markdown
Collaborator

Motivation

  • Ensure that when a value is annotated as a function type the runtime verifies the actual function matches the annotated signature (params/return/async/rest).
  • Reuse existing Type structures and types_compatible logic for comparing function parameter and return types.
  • Provide a clear runtime error that reports both the expected and actual function signatures to aid debugging.
  • Add interpreter tests that exercise mismatched function signatures so the behavior is specified.

Description

  • Added a helper type_matches_function_signature(Type *expected_type, Function *func, const char **error_msg) that constructs a temporary Type for the actual function and validates async flag, parameter count/types, rest param, and return type using types_compatible and type_to_string for formatting.
  • Updated convert_to_type so when the target_type is TYPE_FUNCTION and the value is VAL_FUNCTION it calls the helper and emits a runtime error with both expected and actual signatures if validation fails.
  • Reused existing type machinery (Type, types_compatible, type_to_string) rather than introducing new signature representations.
  • Added interpreter tests tests/functions/function_signature_param_error.hml and tests/functions/function_signature_return_error.hml with corresponding .expected files asserting the runtime error messages.

Testing

  • Added two interpreter tests: tests/functions/function_signature_param_error.hml and tests/functions/function_signature_return_error.hml with expected outputs showing the mismatch messages.
  • No automated test runner was executed as part of this change (tests were added but not run).
  • The new runtime error message format is: Function signature mismatch (expected <expected_sig>, got <actual_sig>).
  • Manual build/CI execution is recommended to run the full test suite and verify no regressions.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant