flan/test/programs/shadow-pkg.flan
Joseph Ferano 79a8142b78 A local shadowing an imported name, in an expression and in a place
Qualification rewrites a package's own names wherever they are used and
has to stop at a binding. Nothing refuses a renamer that does not: the
program builds, runs, and reads the top-level name instead. The package
in shadow-pkg.flan binds locals called limit and sink over its own
constant and var, and the four numbers separate the two halves —
dropping the shadowing check in the expression renamer gives 5, dropping
it in the place renamer moves the 20 onto the package's sink.
2026-09-12 10:40:47 +07:00

22 lines
832 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)
(defvar 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))