Add typed Kotlin JSONObject string constructor
ober
fccc76e702602c0538c28935ef7b5e228947bded
--- a/lib/jerboa/typed/checker.ss +++ b/lib/jerboa/typed/checker.ss @@ -548,6 +548,9 @@ (cons 'json-object-empty (make-typed-call-sig '() 'JSONObject '() 'jvm-json-object-empty '())) + (cons 'json-object-from-string + (make-typed-call-sig (list 'String) 'JSONObject '() + 'jvm-json-object-from-string '())) (cons 'json-object-copy (make-typed-call-sig (list 'JSONObject) 'JSONObject '() 'jvm-json-object-copy '())) --- a/lib/jerboa/typed/core.ss +++ b/lib/jerboa/typed/core.ss @@ -160,6 +160,7 @@ jvm-json-array-length jvm-json-array-opt-float32 jvm-json-object-empty + jvm-json-object-from-string jvm-json-object-copy jvm-json-object-put-string jvm-json-object-put-int --- a/lib/jerboa/typed/kotlin/lower.ss +++ b/lib/jerboa/typed/kotlin/lower.ss @@ -476,6 +476,8 @@ '())] [(jvm-json-object-empty) (make-kt-new (make-kt-type 'JSONObject #f '()) '())] + [(jvm-json-object-from-string) + (make-kt-new (make-kt-type 'JSONObject #f '()) args)] [(jvm-json-object-copy) (make-kt-new (make-kt-type 'JSONObject #f '()) --- a/tests/test-typed-kotlin.ss +++ b/tests/test-typed-kotlin.ss @@ -816,7 +816,7 @@ (define json-object-form '(typed-library (sample typed json-object) - (export makeCell copyCell readX readXDefault readCount readActive readItems readMeta readName readNameDefault) + (export makeCell parseCell copyCell readX readXDefault readCount readActive readItems readMeta readName readNameDefault) (type JSONObject) (type JSONArray) (type Float32) @@ -835,6 +835,8 @@ (json-object-put-json-array! json "mean_bgr" mean) (json-object-put-json-object! json "meta" meta) json))))) + (def (parseCell (text : String)) : JSONObject + (json-object-from-string text)) (def (copyCell (json : JSONObject)) : JSONObject (json-object-copy json)) (def (readX (json : JSONObject)) : Float32 @@ -861,6 +863,9 @@ (test-contains "JSONObject empty lowers to constructor" json-object-kotlin "val json: JSONObject = JSONObject()") +(test-contains "JSONObject from String lowers to string constructor" + json-object-kotlin + "JSONObject(text)") (test-contains "JSONObject copy lowers through string constructor" json-object-kotlin "JSONObject(json.toString())")