diff --git a/org/slot.org b/org/slot.org index 6185ff5..5f5e0e0 100644 --- a/org/slot.org +++ b/org/slot.org @@ -93,8 +93,8 @@ the first call and frozen for subsequent calls: The ~render-fn~ itself is returned so callers can use it inline. -The mode parameter is accepted but only respected on the first -registration for a slot. This prevents a later registration from +The mode parameter is validated on first call via ~assert~ and then +frozen for subsequent calls. This prevents a later registration from changing the slot's semantics out from under earlier registrations. #+BEGIN_SRC lisp :tangle ../src/components/slot.lisp @@ -102,10 +102,14 @@ changing the slot's semantics out from under earlier registrations. (let* ((key (string name)) (slot (gethash key *slots*))) (if (null slot) - ;; First registration — set mode and create entry - (setf (gethash key *slots*) - (list :mode mode - :entries (list (cons order render-fn)))) + ;; First registration — validate and set mode, create entry + (progn + (assert (member mode '(:stack :replace :single-winner)) () + "Invalid slot mode: ~S (use :stack, :replace, or :single-winner)" + mode) + (setf (gethash key *slots*) + (list :mode mode + :entries (list (cons order render-fn))))) ;; Existing slot — respect frozen mode (let ((entries (getf slot :entries))) (ecase (getf slot :mode) diff --git a/src/components/slot.lisp b/src/components/slot.lisp index f0fa409..6ee7a27 100644 --- a/src/components/slot.lisp +++ b/src/components/slot.lisp @@ -8,10 +8,14 @@ Each entry: (:mode :entries <(order . render-fn) list>).") (let* ((key (string name)) (slot (gethash key *slots*))) (if (null slot) - ;; First registration — set mode and create entry - (setf (gethash key *slots*) - (list :mode mode - :entries (list (cons order render-fn)))) + ;; First registration — validate and set mode, create entry + (progn + (assert (member mode '(:stack :replace :single-winner)) () + "Invalid slot mode: ~S (use :stack, :replace, or :single-winner)" + mode) + (setf (gethash key *slots*) + (list :mode mode + :entries (list (cons order render-fn))))) ;; Existing slot — respect frozen mode (let ((entries (getf slot :entries))) (ecase (getf slot :mode)