interop

Crispin 2023-05-25T14:56:26.160399Z

Hi there, Im trying to remove reflection on a ^bytes type hinted parameter to a java call. If I type hint the byte-array directly, it works, but if I type hint a (when ..) to enable a null to be passed in, the reflection cant find the call, and thinks its a java.lang.Object, not a bytes! Any idea what is going on here and how to type hint this correctly?

Crispin 2023-05-25T14:56:59.598239Z

code that works:

(KeyPair/load
      ^JSch (references/get-instance agent)
      ^bytes (utils/decode-base64 private-key-bytes)
      ^bytes (utils/decode-base64 public-key-bytes))

Crispin 2023-05-25T14:57:33.925869Z

code that doesn't:

(KeyPair/load
      ^JSch (references/get-instance agent)
      ^bytes (when private-key-bytes (utils/decode-base64 private-key-bytes))
      ^bytes (when public-key-bytes (utils/decode-base64 public-key-bytes)))

Crispin 2023-05-25T14:57:50.164239Z

results in a call to static method load on com.jcraft.jsch.KeyPair can't be resolved (argument types: com.jcraft.jsch.JSch, java.lang.Object, java.lang.Object).

Crispin 2023-05-25T14:58:07.808049Z

suddenly they are java.lang.Object which is wrong

Crispin 2023-05-25T14:58:31.313279Z

(the code works with reflection... I just would like to remove it)

Alex Miller (Clojure team) 2023-05-25T14:58:46.428289Z

you might want to pull the expr out into a let

Crispin 2023-05-25T15:01:11.447029Z

alright, yeah that now resolves the right static method.

Crispin 2023-05-25T15:01:34.301129Z

Is it because when is a macro?

Crispin 2023-05-25T15:01:49.978249Z

somehow loses the metadata?

Crispin 2023-05-25T15:03:12.632339Z

thanks @alexmiller