Hi. I'm enjoying using core-typed. Thank you for making it!
I'm stuck on type inference, I get this error both when using the lein-typed plugin or from my code attempting to call clojure.core.typed/prepare-infer-ns
No ns provided to infer annotations, defaulting to vtyped.core
Registering annotations from typed.ann.clojure...
Refreshing runtime inference
Registering annotations from typed.ann.clojure...
AssertionError Assert failed: FIXME
(and (not should-runtime-infer?) (not should-runtime-check?))
Any tips on how to get past this?Ah, I think I broke this functionality when moving away from tools.analyzer.
Got it. I just tried using [org.clojure/core.typed "0.4.0"] and that worked 🙂
Yeah, seems like I broke this in 2018. Wow 🙂
[org.typedclojure/typed.clj.runtime "1.0.15"] and higher give an error
I'm struggling to remember all the context.
🙂
I'm trying to annotate the following with "1.0.15":
(t/ann mapper ObjectMapper)
(def ^:private ^ObjectMapper mapper (new ObjectMapper))
(t/ann getJsonNodeFromStringContent [t/Str :-> JsonNode])
(defn ^:private getJsonNodeFromStringContent ^JsonNode [^String content]
(.readTree mapper content))
And I get an error: Actual: (t/U nil JsonNode)
Which I take to mean that typedClojure thinks that readTree can return null.
Changing it to (t/U nil JsonNode) gets past that problem, but then subsequent problems arise for:
(t/ann getJsonSchemaFromJsonNodeAutomaticVersion [JsonNode :-> JsonSchema])
(defn ^:private getJsonSchemaFromJsonNodeAutomaticVersion ^JsonSchema [^JsonNode jsonNode]
(let [factory (JsonSchemaFactory/getInstance (SpecVersionDetector/detect jsonNode))]
(.getSchema factory jsonNode)))
because jsonNode is required, so a (t/U nil JsonNode) doesn't make sense.
Is there something special about readTree that is causing JsonNode to be insufficient? Or do all interop calls assume they could return null? (And if so, how can I chain interop calls?)
The fully qualified classes are:
(:import (com.fasterxml.jackson.databind JsonNode ObjectMapper)
(com.networknt.schema JsonSchema JsonSchemaFactory SpecVersionDetector))
I guess one answer is to restructure the code or skip type checking 🙂
Yes, by default interop ops are nullable return.
There is a way to override it per method.
Oh nice, that makes sense. What is the override?
I think it moved to typed.clojure.jvm in the new ns structure.
👍 thank you