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:
assert_value_matches_type— given aVmValueand aTypeExpr, decide whether the value satisfies the type. The single source of runtime truth forint/string/list<T>/… compatibility, mirroring the static [TypeChecker::types_compatible] semantics on values rather than type expressions.validate_user_call— arity check + per-arg declared-type assertion for compiled user-defined functions (crate::chunk::CompiledFunction).validate_builtin_call— arity check + per-arg type assertion for builtins, driven by the parser’sharn_parser::builtin_signaturesregistry. The runtime never re-implements per-builtin validation; the registry is the contract.
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
valuesatisfiesexpected. ReturnsOk(())when the value is acceptable, otherwise anVmError::ArgTypeMismatchtagged withcallee/param/spanfor 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
TypeExprin theircrate::chunk::ParamSlot.