When using java classes for interop like java.io.File the type checker doesn't seem to automatically understand the types and associated functions but if we do an instance? check it will then work. Is that just how it has to be done right now for java classes/interop or are we doing something wrong?
Something might be wrong or an annotation is needed.
are you calling File methods or just passing File's around?
Both
But i think the specific errors are about using the methods
ah by default methods have nilable returns and non-nilable arguments. Do you get a (Nilable File) instead of a File sometimes?
Hmm so do you think we can just nil check it instead of instance? checking?
If you can tell me the methods in question I can probably tell you how to override the annotation.
assuming it makes sense to
Ok let me check
So a function like io/file the returned value is a file but we have to instance? check it before passing it into another interop function that accepts a file like ImageIO/read
hmm no that doesn't sound right. AFAIK io/file returns a File
Here is an example from one of my devs not the exact scenario we were discussing but similar.
"I'll explain the next issue, which is for the functions that call .drawImage, which is resize-image and save-jpg version. Domains: java.awt.Image int int java.awt.image.ImageObserver Arguments: BufferedImage (t/Val 0) (t/Val 0) nil Ranges: boolean in: (.drawImage graphics image 0 0 nil) The difference is definitely the nil, but the function can for sure accept nil from all the research I did (as well as the fact that it's working correctly). The ImageObserver is an optional object that recieves updates as the image is rendered essentially. My question for this one would be, how can we override or add an Option to the types already present in the java method? I see how to do so on things that come from clojure requires, but couldn't quite figure out how to do so for full Java imports"
Let me find the answer, it's supported.
https://github.com/typedclojure/typedclojure/blob/d51056321ec05d07c778355f81732a830f4341a6/typed/clj.runtime/src/clojure/core/typed.cljc#L436-L446 Try something like this:
(t/nilable-param ImageIO/drawImage {4 #{3}})This is not well documented but I think that's it. LMK and I can investigate further.
Ok thanks we'll try it out