Clojure

[core.specs] spec for fn does not allow anonymous function name

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Declined
  • Affects Version/s: Release 1.9, Release 1.10
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Environment:
    Ubuntu 16.04
    Java 10

Description

In the following macro code fragment, the function ID `fixture-fn` causes the anonymous function to fail clojure.spec:

`(ct/use-fixtures ~mode
   (fn fixture-fn [tgt-fn#]
     (~enter-fn ~ctx)
     (tgt-fn#)
     (~leave-fn ~ctx))))

When function name fixture-fn is absent, compilation proceeds and clojure.spec works fine. When function name is present,
the error message is:

Caused by: clojure.lang.ExceptionInfo: Call to clojure.core/fn did not conform to spec. 

  {:clojure.spec.alpha/problems ({:path [:fn-tail :arity-1 :params], :pred clojure.core/vector?, :val tupelo.test/fixture-fn, 
                                  :via  [:clojure.core.specs.alpha/params+body
                                         :clojure.core.specs.alpha/param-list
                                         :clojure.core.specs.alpha/param-list], :in [0]}
                                 {:path [:fn-tail :arity-n], 
                                  :pred (clojure.core/fn [%] (clojure.core/or 
                                                               (clojure.core/nil? %)
                                                               (clojure.core/sequential? %))),
                                  :val tupelo.test/fixture-fn,
                                  :via [:clojure.core.specs.alpha/params+body
                                        :clojure.core.specs.alpha/params+body], :in [0]}),
  :clojure.spec.alpha/spec #object[clojure.spec.alpha$regex_spec_impl$reify__2509 0x21b8e988 "clojure.spec.alpha$regex_spec_impl$reify__2509@21b8e988"] ,
  :clojure.spec.alpha/value (tupelo.test/fixture-fn [tgt-fn__16599__auto__]
                              ((fn [ctx] (println "*** TEST ONCE *** - enter ")) {:line 25, :column 1})
                              (tgt-fn__16599__auto__)
                              ((fn [ctx] (println "*** TEST ONCE *** - leave ")) {:line 25, :column 1})),
  :clojure.spec.alpha/args (tupelo.test/fixture-fn [tgt-fn__16599__auto__]
                              ((fn [ctx] (println "*** TEST ONCE *** - enter ")) {:line 25, :column 1})
                              (tgt-fn__16599__auto__)
                              ((fn [ctx] (println "*** TEST ONCE *** - leave ")) {:line 25, :column 1}))}

Activity

Hide
Alan Thompson added a comment - - edited

Darn, JIRA destroyed all my nice formatting.... See attached file `jira.clj` for formatted source code and error message

Show
Alan Thompson added a comment - - edited Darn, JIRA destroyed all my nice formatting.... See attached file `jira.clj` for formatted source code and error message
Hide
Alex Miller added a comment -

Fixed the formatting for you

Show
Alex Miller added a comment - Fixed the formatting for you
Hide
Alex Miller added a comment -

The problem here I think is that the syntax quote will fully resolve fixture-fn and the spec requires an unqualified symbol in a function name. You can easily fix that by preventing resolution but leaving the symbol:

`(ct/use-fixtures ~mode
   (fn ~'fixture-fn [tgt-fn#]
     (~enter-fn ~ctx)
     (tgt-fn#)
     (~leave-fn ~ctx))))

Would appreciate if you could try that and see if it works.

Show
Alex Miller added a comment - The problem here I think is that the syntax quote will fully resolve fixture-fn and the spec requires an unqualified symbol in a function name. You can easily fix that by preventing resolution but leaving the symbol:
`(ct/use-fixtures ~mode
   (fn ~'fixture-fn [tgt-fn#]
     (~enter-fn ~ctx)
     (tgt-fn#)
     (~leave-fn ~ctx))))
Would appreciate if you could try that and see if it works.
Hide
Alex Miller added a comment -

I'm about 99% sure this is the issue. A minimal repro would be something like:

(fn a/b [])

which should just be:

(fn b [])
Show
Alex Miller added a comment - I'm about 99% sure this is the issue. A minimal repro would be something like:
(fn a/b [])
which should just be:
(fn b [])
Hide
Alex Miller added a comment -

Going to decline this as I believe the issue is in the code, not the spec. If it's not this, please re-open.

Show
Alex Miller added a comment - Going to decline this as I believe the issue is in the code, not the spec. If it's not this, please re-open.
Hide
Alan Thompson added a comment -

You are correct. Using

~'fixture-fn

solved the issue.

Show
Alan Thompson added a comment - You are correct. Using ~'fixture-fn solved the issue.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: