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

Context not set for PersistentList #162

Closed
luxbock opened this issue Mar 14, 2016 · 6 comments
Closed

Context not set for PersistentList #162

luxbock opened this issue Mar 14, 2016 · 6 comments

Comments

@luxbock
Copy link

luxbock commented Mar 14, 2016

I assume the following should work.

New project with Clojure 1.8.0 and cats 1.2.1:

(ns catsss.core
  (:require [cats.builtin]
            [cats.core :as m]))

(m/fmap inc '(1 2 3))

throws:

1. Unhandled java.lang.IllegalArgumentException
   No context is set and it can not be automatically resolved.

NativeConstructorAccessorImpl.java:   -2  sun.reflect.NativeConstructorAccessorImpl/newInstance0
NativeConstructorAccessorImpl.java:   57  sun.reflect.NativeConstructorAccessorImpl/newInstance
DelegatingConstructorAccessorImpl.java:   45  sun.reflect.DelegatingConstructorAccessorImpl/newInstance
          Constructor.java:  526  java.lang.reflect.Constructor/newInstance
            Reflector.java:  180  clojure.lang.Reflector/invokeConstructor
              context.cljc:   34  cats.context$throw_ilegal_argument/invokeStatic
              context.cljc:   34  cats.context$throw_ilegal_argument/invoke
              context.cljc:   87  cats.context$get_current/invokeStatic
              context.cljc:   66  cats.context$get_current/invoke
                 core.cljc:  129  cats.core$fmap/invokeStatic
                 core.cljc:  122  cats.core$fmap/invoke
                      REPL:    9  catsss.core/eval23254

I'm not sure why it doesn't though, as I see in cats.builtin that it should already be extended. If I do the same manually in my REPL then everything works as expected.

@yurrriq
Copy link
Collaborator

yurrriq commented Mar 14, 2016

Hmm. I'm not sure about this one off the top of my head. Maybe @dialelo or @niwinz have a quick answer. Thanks for the report.

@niwinz
Copy link
Member

niwinz commented Mar 14, 2016

It is very strange, because we have the same thing in tests and it works as expected :S

@c-garcia
Copy link

c-garcia commented May 1, 2016

Hi

Same here. Very small project just for testing cats and promesa:

(defproject slack-wb "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.8.0"]
                 [http-kit "2.1.18"]
                 [cheshire "5.6.1"]
                 [funcool/promesa "1.1.1"]
                 [funcool/cats "1.2.1"]])

The offending function

(ns slack-wb.sandbox
  (:require [org.httpkit.client :as http]
            [cheshire.core :refer :all]
            [promesa.core :as p]
            [cats.core :as m]
            [cats.builtin]
            [cats.monad.maybe :as maybe]
            [cats.monad.either :as either]))

(defn ee
  [x]
  (m/fmap inc '(1 2 3 (Integer/parseInt x))))

(defn -main
  [& args]
  (ee (first args)))

Either from the repl or running the code from leiningen, the result is the same:

$ lein run -m slack-wb.sandbox
Exception in thread "main" java.lang.IllegalArgumentException: No context is set and it can not be automatically resolved., compiling:(/private/var/folders/p2/22f9bht534b7d81ybhyyghf40000gn/T/form-init3677970153629996767.clj:1:125)
    at clojure.lang.Compiler.load(Compiler.java:7391)
    at clojure.lang.Compiler.loadFile(Compiler.java:7317)
    at clojure.main$load_script.invokeStatic(main.clj:275)
    at clojure.main$init_opt.invokeStatic(main.clj:277)
    at clojure.main$init_opt.invoke(main.clj:277)
    at clojure.main$initialize.invokeStatic(main.clj:308)
    at clojure.main$null_opt.invokeStatic(main.clj:342)
    at clojure.main$null_opt.invoke(main.clj:339)
    at clojure.main$main.invokeStatic(main.clj:421)
    at clojure.main$main.doInvoke(main.clj:384)
    at clojure.lang.RestFn.invoke(RestFn.java:421)
    at clojure.lang.Var.invoke(Var.java:383)
    at clojure.lang.AFn.applyToHelper(AFn.java:156)
    at clojure.lang.Var.applyTo(Var.java:700)
    at clojure.main.main(main.java:37)
Caused by: java.lang.IllegalArgumentException: No context is set and it can not be automatically resolved.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at clojure.lang.Reflector.invokeConstructor(Reflector.java:180)
    at cats.context$throw_ilegal_argument.invokeStatic(context.cljc:34)
    at cats.context$throw_ilegal_argument.invoke(context.cljc:34)
    at cats.context$get_current.invokeStatic(context.cljc:87)
    at cats.context$get_current.invoke(context.cljc:66)
    at cats.core$fmap.invokeStatic(core.cljc:129)
    at cats.core$fmap.invoke(core.cljc:122)
    at slack_wb.sandbox$ee.invokeStatic(sandbox.clj:23)
    at slack_wb.sandbox$ee.invoke(sandbox.clj:21)
    at slack_wb.sandbox$_main.invokeStatic(sandbox.clj:27)
    at slack_wb.sandbox$_main.doInvoke(sandbox.clj:25)
    at clojure.lang.RestFn.invoke(RestFn.java:397)
    at clojure.lang.Var.invoke(Var.java:375)
    at user$eval5.invokeStatic(form-init3677970153629996767.clj:1)
    at user$eval5.invoke(form-init3677970153629996767.clj:1)
    at clojure.lang.Compiler.eval(Compiler.java:6927)
    at clojure.lang.Compiler.eval(Compiler.java:6917)
    at clojure.lang.Compiler.load(Compiler.java:7379)
    ... 14 more

Just in case it helps, the java version is:

java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

On MacOS X 10.10.5

HTH and thanks in advance

Cristóbal

@niwinz
Copy link
Member

niwinz commented May 1, 2016

Seems like the bug is fixed but is not yet released. In master it works as expected.

Be bug consists that list does not have implemenation of Functor.

@niwinz niwinz closed this as completed May 1, 2016
@niwinz
Copy link
Member

niwinz commented May 1, 2016

In any case, your code will raise an other exception, because '(1 2 3 (Integer/parseInt x)) will not be evaluated so, the forth element of that list is (Integer/parseInt x) instead of the result of executing that.

Use (list 1 2 3 (Integer/parseInt x)) for that purpose.

@c-garcia
Copy link

c-garcia commented May 1, 2016

👍 You are definitely right. I put some code aside in order to make the issue reproducible by you guys and missed the implications of the quote.

Thanks for your help and best regards

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

4 participants