Add typed Kotlin JSON object copy

ober

988ee3ae1c7d44aa154b824620e515899fc4863a

diff --git a/lib/jerboa/typed/checker.ss b/lib/jerboa/typed/checker.ss
index 27f6264..b346a28 100644
--- a/lib/jerboa/typed/checker.ss
+++ b/lib/jerboa/typed/checker.ss
@@ -521,6 +521,9 @@
       (cons 'json-object-empty
             (make-typed-call-sig '() 'JSONObject '()
               'jvm-json-object-empty '()))
+      (cons 'json-object-copy
+            (make-typed-call-sig (list 'JSONObject) 'JSONObject '()
+              'jvm-json-object-copy '()))
       (cons 'json-object-put-string!
             (make-typed-call-sig (list 'JSONObject 'String 'String) 'Unit '()
               'jvm-json-object-put-string '()))
diff --git a/lib/jerboa/typed/core.ss b/lib/jerboa/typed/core.ss
index 7b610b7..82526cb 100644
--- a/lib/jerboa/typed/core.ss
+++ b/lib/jerboa/typed/core.ss
@@ -150,6 +150,7 @@
       jvm-json-array-length
       jvm-json-array-opt-float32
       jvm-json-object-empty
+      jvm-json-object-copy
       jvm-json-object-put-string
       jvm-json-object-put-int32
       jvm-json-object-put-float32
diff --git a/lib/jerboa/typed/kotlin/lower.ss b/lib/jerboa/typed/kotlin/lower.ss
index abecc50..341578c 100644
--- a/lib/jerboa/typed/kotlin/lower.ss
+++ b/lib/jerboa/typed/kotlin/lower.ss
@@ -433,6 +433,10 @@
            '())]
         [(jvm-json-object-empty)
          (make-kt-new (make-kt-type 'JSONObject #f '()) '())]
+        [(jvm-json-object-copy)
+         (make-kt-new
+           (make-kt-type 'JSONObject #f '())
+           (list (make-kt-member-call (car args) 'toString '())))]
         [(jvm-json-object-put-string)
          (make-kt-block
            (list
diff --git a/tests/test-typed-checker.ss b/tests/test-typed-checker.ss
index 7f62045..144e966 100644
--- a/tests/test-typed-checker.ss
+++ b/tests/test-typed-checker.ss
@@ -936,7 +936,7 @@
 (test "json-object primitives accept declared JSON types"
   (error-kinds
     '(typed-library (body json-object-ok)
-       (export make-json read-x read-x-default)
+       (export make-json copy-json read-x read-x-default)
        (type JSONObject)
        (type JSONArray)
        (type Float32)
@@ -951,6 +951,8 @@
                (json-object-put-int32! json "count" n)
                (json-object-put-json-array! json "items" items)
                json))))
+       (def (copy-json (json : JSONObject)) : JSONObject
+         (json-object-copy json))
        (def (read-x (json : JSONObject)) : Float32
          (json-object-opt-float32 json "x"))
        (def (read-x-default (json : JSONObject)) : Float32
diff --git a/tests/test-typed-kotlin.ss b/tests/test-typed-kotlin.ss
index 1af7cc6..b58c2a9 100644
--- a/tests/test-typed-kotlin.ss
+++ b/tests/test-typed-kotlin.ss
@@ -734,7 +734,7 @@
 
 (define json-object-form
   '(typed-library (sample typed json-object)
-     (export makeCell readX readXDefault readCount readItems readMeta readName readNameDefault)
+     (export makeCell copyCell readX readXDefault readCount readItems readMeta readName readNameDefault)
      (type JSONObject)
      (type JSONArray)
      (type Float32)
@@ -751,6 +751,8 @@
                (json-object-put-json-array! json "mean_bgr" mean)
                (json-object-put-json-object! json "meta" meta)
                json)))))
+     (def (copyCell (json : JSONObject)) : JSONObject
+       (json-object-copy json))
      (def (readX (json : JSONObject)) : Float32
        (json-object-opt-float32 json "x"))
      (def (readXDefault (json : JSONObject)) : Float32
@@ -771,6 +773,9 @@
 (test-contains "JSONObject empty lowers to constructor"
   json-object-kotlin
   "val json: JSONObject = JSONObject()")
+(test-contains "JSONObject copy lowers through string constructor"
+  json-object-kotlin
+  "JSONObject(json.toString())")
 (test-contains "JSONObject put String lowers directly"
   json-object-kotlin
   "json.put(\"id\", id)")