babashka / sci

Configurable Clojure/Script interpreter suitable for scripting and Clojure DSLs
Eclipse Public License 1.0
1.22k stars 89 forks source link

Divergence from ClojureJVM when referencing a var with a full stop (.) in the name #811

Closed pmonks closed 1 year ago

pmonks commented 2 years ago

version

JVM 17.0.4.1+1 (Linux/amd64) with Clojure 1.11.1 JVM 17.0.4.1+1 (Mac OS X/x86_64) with Clojure 1.10.3 sci 0.4.33

platform

Linux macOS

problem

sci accepts a full stop (.) character when referencing a var name, when ClojureJVM does not.

repro

(defn invalid.varname [x] x)
(invalid.varname :foo)

actual behavior (sci)

:foo

expected behavior (ClojureJVM)

Syntax error (ClassNotFoundException) compiling at (REPL:1:1).
invalid.varname

or similar error message appropriate to sci.

additional context

This is probably a very low priority corner case I realise, but it would be nice if sci more closely followed Clojure's behaviour here.

borkdude commented 1 year ago

Although this isn't enforced by defn in Clojure (you can still define vars using this name), just because the name has a ., it only considers this to be a class. Note that this does work:

user=> (#'invalid.varname 1)
1

In CLJS the behavior is even more fuzzy since (invalid.varname :foo) could mean ((.-varname invalid) :foo). I think I'd rather implementing this as a clj-kondo rule "var name should be symbol without dots" rather than doing extra checks during SCI analysis. I'll make an issue for that.

borkdude commented 1 year ago

Note that this also works:

user=> (user/invalid.varname 1)
1