core-typed

timothypratley 2023-07-17T17:22:38.576379Z

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?

2023-07-17T18:29:17.224049Z

Ah, I think I broke this functionality when moving away from tools.analyzer.

timothypratley 2023-07-17T18:48:43.427999Z

Got it. I just tried using [org.clojure/core.typed "0.4.0"] and that worked 🙂

2023-07-17T18:49:16.479659Z

Yeah, seems like I broke this in 2018. Wow 🙂

timothypratley 2023-07-17T18:49:22.836179Z

[org.typedclojure/typed.clj.runtime "1.0.15"] and higher give an error

2023-07-17T18:49:25.531399Z

I'm struggling to remember all the context.

timothypratley 2023-07-17T18:49:31.948999Z

🙂

timothypratley 2023-07-17T19:20:32.049219Z

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))

timothypratley 2023-07-17T19:22:39.887279Z

I guess one answer is to restructure the code or skip type checking 🙂

2023-07-17T19:22:42.311779Z

Yes, by default interop ops are nullable return.

2023-07-17T19:22:51.899449Z

There is a way to override it per method.

timothypratley 2023-07-17T19:23:36.361349Z

Oh nice, that makes sense. What is the override?

2023-07-17T19:24:45.927239Z

I think it moved to typed.clojure.jvm in the new ns structure.

timothypratley 2023-07-17T19:25:03.654229Z

👍 thank you