1
0
forked from alex-eg/sex

refuse a macro defined after a call to it

The call was compiled as a function's, and the macro went unused there
without a word.
This commit is contained in:
2026-10-19 14:48:43 +03:00
parent 9505b4f0a0
commit af8e49cdd3
2 changed files with 30 additions and 1 deletions

View File

@@ -335,6 +335,14 @@
"macro takes at least this many arguments many 1"))
(test-assert "while it may take any more"
(emits? "(defmacro (many x . more) x) (fn f () int (return (many 1 2 3)))" "return 1;"))
;; a call before the macro is defined is a function call, and the
;; macro defined after it went unused there without a word
(test-assert "a macro defined after a call to it is refused"
(reports? "(fn f () int (return (later 1)))\n(defmacro (later x) x)"
"codegen.sex:2: a macro defined after a call to it"))
(test-assert "naming where the call is"
(reports? "(fn f () int\n (return (later 1)))\n(defmacro (later x) x)"
"/codegen.sex:2\""))
(test-assert "an error in a macro's body names the call"
(reports? "(defmacro (boom x) (error \"no good\" x))\n(fn f () int (return (boom 1)))"
"codegen.sex:2: expanding boom: no good")))