Fwd: nREPL Middleware error

67 views
Skip to first unread message

Ambrose Bonnaire-Sergeant

unread,
Apr 9, 2015, 7:37:01 PM4/9/15
to clojur...@googlegroups.com
Hi,

I'm adding some REPL middleware for type checking with core.typed.

Here I'm sending a response packet that contains an evaluated result after type checking.

Once core.typed kicks in, something goes wrong, then a few CTRL-C's reveals the stacktrace below.

Any thoughts welcome.

Reflection warning, /tmp/form-init522527866366857395.clj:1:3831 - reference to field name can't be resolved.
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

""
"ns-form?" false
"FINISHED"
user=> (ns ^:core.typed baZ)
"(ns ^:core.typed baZ)"
"ns-form?" true
Initializing core.typed ...
combinatorics.clj:312 recur arg for primitive local: acc is not matching primitive, had: Object, needed: long
Auto-boxing loop arg: acc
combinatorics.clj:520 recur arg for primitive local: y is not matching primitive, had: Object, needed: long
Auto-boxing loop arg: y
combinatorics.clj:613 recur arg for primitive local: index is not matching primitive, had: Object, needed: long
Auto-boxing loop arg: index
combinatorics.clj:621 recur arg for primitive local: index is not matching primitive, had: Object, needed: long
Auto-boxing loop arg: index
Reflection warning, clojure/core/memoize.clj:72:23 - reference to field cache can't be resolved.
Found ClojureScript, loading ...
Reflection warning, cljs/core.clj:898:31 - reference to field getNamespace can't be resolved.
Reflection warning, cljs/core.clj:898:57 - reference to field getName can't be resolved.
Reflection warning, cljs/core.clj:898:31 - reference to field getNamespace can't be resolved.
Reflection warning, cljs/core.clj:898:57 - reference to field getName can't be resolved.
Finished loading ClojureScript
Building core.typed base environments ...
DEPRECATED SYNTAX (NO_SOURCE_PATH): Rec syntax is deprecated, use cljs.core.typed/Rec
DEPRECATED SYNTAX (NO_SOURCE_PATH): HVec syntax is deprecated, use cljs.core.typed/HVec
Finished building base environments
"Elapsed time: 22883.417005 msecs"
core.typed initialized.
"Value =" nil
"FINISHED"
nil
"ns-form?" false
"FINISHED"
nil
"ns-form?" false
"FINISHED"
ClassCastException clojure.lang.PersistentArrayMap cannot be cast to [B
clojure.tools.nrepl.bencode/string<payload (bencode.clj:174)
clojure.tools.nrepl.bencode/read-map/fn--7357 (bencode.clj:287)
clojure.core/map/fn--4245 (core.clj:2559)
clojure.lang.LazySeq.sval (LazySeq.java:40)
clojure.lang.LazySeq.seq (LazySeq.java:49)
clojure.lang.Cons.next (Cons.java:39)
clojure.lang.RT.next (RT.java:598)
clojure.core/next (core.clj:64)
clojure.core.protocols/fn--6086 (protocols.clj:146)
clojure.core.protocols/fn--6057/G--6052--6066 (protocols.clj:19)
clojure.core.protocols/seq-reduce (protocols.clj:31)
clojure.core.protocols/fn--6078 (protocols.clj:54)
Bye for now!

Thanks,
Ambrose

Chas Emerick

unread,
Apr 10, 2015, 10:15:07 AM4/10/15
to clojur...@googlegroups.com
Hi Ambrose,

The `result` coming out of `check-form-info` is not the result of evaluating the submitted code. It seems like it's often nil, which (if you're indicating that it's already in a printed form via :printed-value) is not valid (it needs to be a string, hopefully readable). I suspect that nil puts the bencode encoder (or some other part of the stack) into a rare state. I'll dig into that separately later.

What you should do depends a lot on how you want the interaction to work. My intuition is that there's two likely modes:

1. Type-check the submitted expression, and emit errors from that analysis as warnings, but still evaluate the code.
2. If the expression fails to type-check, suppress evaluation, and emit the nREPL messages corresponding to effectively an evaluation error.

Neither are complicated, but the first is easier, so that's what I did here:

https://gist.github.com/cemerick/2766ab4a9e47ee8ee299

Basically, it's just dumping the result of type checking to *out*/*err*, and letting all other nREPL handler processing proceed regardless of those results. An example of the output is in the linked gist above, too.

I know you're just hacking around right now, but a couple of suggestions:

* you really shouldn't have to (flush)
* It's rarely a good idea to sniff the expressions sent for evaluation. Seems like the the `typed?` value is entirely sufficient to determine what to do?

I hope that's helpful?

- Chas
--
You received this message because you are subscribed to the Google Groups "clojure-tools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure-tool...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages