Skip to main content

Module typecheck

Module typecheck 

Source
Expand description

Runtime type & arity validation, shared between user-defined function calls and registry-known builtin calls.

Every call-site validation in the VM funnels through three entry points:

All three return crate::value::VmError variants (VmError::ArityMismatch, VmError::ArgTypeMismatch) on failure so error UX is uniform. Callers may pass an optional harn_lexer::Span when they have a source location for the call site (e.g. derived from the chunk’s PC→span table); when omitted the error renders without a positional suffix.

Functions§

assert_value_matches_type
Validate that value satisfies expected. Returns Ok(()) when the value is acceptable, otherwise an VmError::ArgTypeMismatch tagged with callee / param / span for the caller’s diagnostic.
validate_against_signature
Shared implementation for validate_builtin_call (and any future callers that already have a signature in hand). Public so test harnesses can drive it directly with synthetic signatures.
validate_builtin_call
Validate a builtin call against the parser’s signature registry. Returns Ok(()) when the builtin is unknown to the registry — the alignment guarantee enforced at registration time means unknown names are necessarily internal/special-purpose builtins (e.g. compiler-synthesized __*) that don’t need runtime validation.
validate_user_call
Validate a user-defined function call: arity (respecting defaults + rest), then per-parameter declared-type assertion for parameters that carry a TypeExpr in their crate::chunk::ParamSlot.