Fork me on GitHub
#clojure-spec
<
2023-06-22
>
Chris Lester21:06:37

I have a strange error (because I can't find any references to this) on having a spec from another namespace that is only required and used in a (comment ...) block causing a compile failure. Is that a special case similar to unknown reader tags in the comment block that will cause it to fail since it attempts to parse that anyway?

seancorfield21:06:20

You mean this reader error:

> clj
Clojure 1.11.1
user=> (comment
    (require '[foo.bar :as quux])
    ::quux/wibble
Syntax error reading source at (REPL:4:0).
Invalid token: ::quux/wibble
user=>

seancorfield21:06:26

That's because the contents of the comment must be syntactically valid Clojure tokens, and because the require is runtime and not evaluated, the auto-resolving keyword prefix ::quux cannot be expanded.

seancorfield21:06:33

You could either add the require to your ns (even tho' it wouldn't be used elsewhere -- you could use :as-alias instead of :as if you don't want it to be actually loaded assuming you're on a recent enough version of Clojure) or you could use the fully-qualified Spec name instead of using the alias.

Chris Lester21:06:36

Thanks Sean, makes sense, I added a partner dev who cleaned up that namespace since it wasn’t used (coming from a typed language and the non use of that ns bugged him).