If the format string ends in ~@, there is code in cl-format to detect this
and issue a format-error. However, that error detection is wrong, and a null exception
happens rather than the format-error being reported.
To reproduce this, simply evaluate the following.
clojure.pprint> (cl-format false "~@")
Execution error (NullPointerException) at nrepl.middleware.interruptible-eval/evaluate$fn$fn (interruptible_eval.clj:87).
I have a fix for this which I'd like to contribute.
Here is the new version of the code compile-directive
(defn- compile-directive [s offset]
(let [[raw-params [rest offset]] (extract-params s offset)
[_ [rest offset flags]] (extract-flags rest offset)
directive (first rest)
;; previous version was missing (if directive ...) here thus (format-error ...) never reached
def (if directive (get directive-table (Character/toUpperCase ^Character directive)))
params (if def (map-params def (map translate-param raw-params) flags offset))]
(if (not directive)
(format-error "Format string ended in the middle of a directive" offset))
(if (not def)
(format-error (str "Directive \"" directive "\" is undefined") offset))
[(struct compiled-directive ((:generator-fn def) params offset) def params offset)
(let [remainder (subs rest 1)
offset (inc offset)
trim? (and (= \newline (:directive def))
(not (:colon params)))
trim-count (if trim? (prefix-count remainder [\space \tab]) 0)
remainder (subs remainder trim-count)
offset (+ offset trim-count)]
[remainder offset])]))
The old version