Skip to content

Commit 060016b

Browse files
hyperpolymathclaude
andcommitted
fix: enforce purity checking in data expressions
@pure/@ToTal markers were parsed and stored but never validated. Impure functions could be called from data expressions, violating the Harvard Architecture security model. Now returns PurityViolation error when impure functions are called from data context. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 58b45f6 commit 060016b

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

crates/jtv-core/src/typechecker.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,24 @@ impl TypeChecker {
437437
.get_func(&qualified)
438438
.or_else(|| self.env.get_func(&call.name));
439439

440-
if let Some((param_types, ret_ty, _)) = func_info {
440+
if let Some((param_types, ret_ty, purity)) = func_info {
441+
// Harvard Architecture enforcement: Data expressions
442+
// may ONLY call Pure or Total functions. Impure functions
443+
// could loop or perform IO, breaking the Totality guarantee
444+
// that makes code injection grammatically impossible.
445+
let purity = purity.clone();
446+
let ret_ty = ret_ty.clone();
447+
let param_types = param_types.clone();
448+
449+
if purity == Purity::Impure {
450+
return Err(JtvError::PurityViolation(format!(
451+
"Data expression calls impure function '{}'. \
452+
Only @pure or @total functions may be called \
453+
from data expressions (Harvard Architecture rule)",
454+
call.qualified_name()
455+
)));
456+
}
457+
441458
// Check argument count
442459
if call.args.len() != param_types.len() {
443460
return Err(JtvError::ArityMismatch {
@@ -457,7 +474,7 @@ impl TypeChecker {
457474
}
458475
}
459476

460-
Ok(ret_ty.clone())
477+
Ok(ret_ty)
461478
} else {
462479
Err(JtvError::UndefinedFunction(qualified))
463480
}

0 commit comments

Comments
 (0)