Lines
100 %
Functions
Branches
//! A macro body that discards a runtime sub-result (a DOLIST over a runtime
//! list here) is the structured expansion-time error, not a silent `nil`.
use rpc::{ScriptCtx, Session};
use uuid::Uuid;
#[tokio::test(flavor = "current_thread")]
async fn a_dolist_over_an_effectful_list_in_a_macro_body_is_refused() {
let mut session = Session::new(ScriptCtx::new(Uuid::new_v4())).unwrap();
let form = "(progn (defmacro m () (dolist (i (progn (print 0) (list 1))) (print i)) nil) (m))";
let resp = session.handle_form(&format!("(:id 1 :form {form})")).await;
assert!(
resp.contains("a macro body cannot use a runtime value or effect at expansion time"),
"got: {resp}"
);
}
async fn a_do_body_burying_an_effect_in_a_let_init_is_refused() {
let form =
"(progn (defmacro m () (do ((i 0 (+ i 1))) ((= i 1)) (let ((x (print i))) nil)) nil) (m))";
async fn a_do_result_form_behind_return_from_is_not_an_expansion_effect() {
let form = "(progn (defmacro m () (block b (do ((i 0 (+ i 1))) ((= i 1) (print 99)) (return-from b 7)))) (m))";
assert!(!resp.contains(":error"), "got: {resp}");
assert!(!resp.contains("99"), "the result form must not run: {resp}");
assert!(resp.contains('7'), "got: {resp}");