flan/test/programs/shadow-pkg.flan
Joseph Ferano a4c6b996ff def re-runs its initialiser, and defvar is renamed defonce
The trio the author decided on 2026-09-20 is now all built: def is CL's
defparameter — its initialiser runs on every daemon re-run, unguarded, so
an edited initialiser repaints the same storage on C-c C-c plus re-run —
defonce (Clojure's name for CL's defvar, per the author) initialises once
behind the .init~once. flag, and defconst stays the image.

One parse arm reads both forms; the difference is Ast.reinit, carried to
Tast.global's grerun. Emit.startup_plan gives a def no guard flag, and
Check.check_global lifts every def initialiser — zero and literal
included — into global/<n>, so the host's startup reaches it through the
function cell and a re-evaluated def swaps it (Session's def_inits;
Emit.redefinition declares the cell for a non-sibling target). The old
defvar spelling is refused with the rename and both compiling spellings,
and every program, test, doc and editor list is swept — except sand.flan,
the author's live WIP, whose seven defvar lines are flagged in FIX.org
and keep its three dependent tests red on this branch.
2026-09-21 07:12:04 +07:00

22 lines
833 B
Plaintext

;;;; A package whose own bodies bind locals named after its own top-level
;;;; names. Imported, every name this file owns is rewritten to shd/name
;;;; wherever it is *used* — and a local binding shadows, so inside these two
;;;; functions the bare name is the local and must be left alone. Get that
;;;; wrong and the code still compiles and still runs; it just reads a
;;;; different variable, which is why this needs a fixture and not a refusal.
(defconst limit 5)
(defonce sink i32)
;;; The expression case: the body's [limit] is the let's, not the constant.
(defn shadowed [] i32
(let [limit 7]
limit))
;;; The place case, which is a separate line in the renamer: [set] takes a
;;; place, and a place that is a bare name has its own shadowing check.
(defn assigned [] i32
(let [sink 0]
(set sink 20)
sink))