Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clojure.spec.alpha/form should return ::undefined for anonym functions #1

Closed
mathesz opened this issue May 13, 2022 · 1 comment
Closed

Comments

@mathesz
Copy link

mathesz commented May 13, 2022

The clojure.spec.alpha/form function calls fn-sym which returns a wrong value for anonym functions:

(defn- fn-sym [^Object f]
  (let [[_ f-ns f-n] (re-matches #"(.*)\$(.*?)(__[0-9]+)?" (.. f getClass getName))]
    ;; check for anonymous function
    (when (not= "fn" f-n)
      (symbol (demunge f-ns) (demunge f-n)))))

https://github.com/babashka/spec.alpha/blob/babashka/src/main/clojure/clojure/spec/alpha.clj#L146-L150
Expected behavior:

The function should return nil for anonym functions.

Current behavior:

Symbolic value of the function is returned, such as sci.impl.fns/fun/arity-0

The regular expression and the when condition fails to ignore sci anonym functions.

(re-matches #"(.*)\$(.*?)(__[-1-9]+)?" "sci.impl.fns$fun$arity_-1__7418@31425281")
=> ["sci.impl.fns$fun$arity_-1__7418@31425281" "sci.impl.fns$fun" "arity_-1__7418@31425281" nil]

The string "arity_-1__7418@31425281" becomes f-n which is not= "fn" , therefore the when condition returns a demunged symbol for the anonym function insted of the correct nil value.

Impact

(clojure.spec.alpha/form (fn [] true)) => sci.impl.fns/fun/arity-0

This should be :clojure.spec.alpha/undefined as per
https://github.com/babashka/spec.alpha/blob/babashka/src/main/clojure/clojure/spec/alpha.clj#L169

@borkdude
Copy link

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants