Fix #1513: interop on Thread/sleep with non-long (#1628)

This commit is contained in:
Michiel Borkent 2023-09-26 21:16:22 +02:00 committed by GitHub
parent 8a8c2dcb46
commit ef50677275
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View file

@ -13,6 +13,7 @@ A preview of the next release can be installed from
- Bump rewrite-clj to v0.1.1.47
- [#1619](https://github.com/babashka/babashka/issues/1619): Fix reflection issue with `Thread/sleep` in `core.async/timeout`
- Support interop on `java.util.stream.IntStream`
- [#1513](https://github.com/babashka/babashka/issues/1513): Fix interop on `Thread/sleep` with numbers that aren't already longs
## 1.3.184 (2023-08-22)

View file

@ -644,7 +644,19 @@
([_# ^String class-name#]
(Class/forName class-name#))
([_# ^String class-name# initialize# ^java.lang.ClassLoader clazz-loader#]
(Class/forName class-name#)))}))]]
(Class/forName class-name#)))})
(= 'java.lang.Thread c)
(assoc :static-methods
{(list 'quote 'sleep)
`(fn
([_# x#]
(if (instance? Number x#)
(let [x# (long x#)]
(Thread/sleep x#))
(let [^java.time.Duration x# x#]
(Thread/sleep x#))))
([_# ^java.lang.Long millis# ^java.lang.Long nanos#]
(Thread/sleep millis# nanos#)))}))]]
c))
m (assoc m :public-class
(fn [v]

View file

@ -44,3 +44,9 @@
(deftest IntStream-test
(is (pos? (bb nil "(.count (.codePoints \"woof🐕\"))"))))
(deftest Thread-sleep-test
(is (bb nil "(Thread/sleep (/ 1 200))
(Thread/sleep (/ 1 200) (/ 1 200))
(Thread/sleep (java.time.Duration/ofMillis 1))
true")))