Lines
100 %
Functions
Branches
// Skipped under Miri: compiling a script builds wasm through wasmtime.
#![cfg(not(miri))]
//! SHOULD-APPLY is a separately compiled function: it reads no runtime
//! variable a function kept from a binder that ended.
const KEEP: &str = "(let ((r (+ 1 (entity-count)))) (defun cnt () r))";
fn compile_error(source: &str) -> String {
rpc::compile_script(source)
.expect_err("a kept runtime variable is not readable")
.to_string()
}
#[test]
fn should_apply_does_not_read_the_runtime_variable_a_function_kept() {
let locals = "(a (+ 7 (entity-count))) (b (+ 7 (entity-count))) (c (+ 7 (entity-count)))";
for test in ["(= (cnt) 1)", "(= (cnt) 7)"] {
let source = format!("{KEEP} (defun should-apply () (let ({locals}) {test}))");
let err = compile_error(&source);
assert!(err.contains("CNT: reads R, a runtime variable"), "{err}");
fn should_apply_without_locals_reads_none_either() {
let err = compile_error(&format!("{KEEP} (defun should-apply () (= (cnt) 1))"));