core-typed

2024-06-10T21:08:41.498619Z

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?

2024-06-11T18:03:25.940159Z

Something might be wrong or an annotation is needed.

2024-06-11T18:04:24.824059Z

are you calling File methods or just passing File's around?

2024-06-11T19:05:27.365449Z

Both

2024-06-11T19:05:39.897479Z

But i think the specific errors are about using the methods

2024-06-11T19:16:54.096399Z

ah by default methods have nilable returns and non-nilable arguments. Do you get a (Nilable File) instead of a File sometimes?

2024-06-11T19:26:30.461709Z

Hmm so do you think we can just nil check it instead of instance? checking?

2024-06-11T19:27:05.996619Z

If you can tell me the methods in question I can probably tell you how to override the annotation.

2024-06-11T19:27:16.661879Z

assuming it makes sense to

2024-06-11T19:27:21.130039Z

Ok let me check

2024-06-11T19:29:11.004649Z

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

2024-06-11T19:32:31.925569Z

hmm no that doesn't sound right. AFAIK io/file returns a File [(t/+ ) :-> java.io.File]

2024-06-11T19:56:44.199109Z

Here is an example from one of my devs not the exact scenario we were discussing but similar.

2024-06-11T19:57:18.941289Z

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

2024-06-11T19:58:07.883829Z

Let me find the answer, it's supported.

2024-06-11T20:01:13.988719Z

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

2024-06-11T20:03:45.647779Z

This is not well documented but I think that's it. LMK and I can investigate further.

2024-06-11T21:16:27.057459Z

Ok thanks we'll try it out