Add typed Kotlin mutable set construction

ober

00a2198245678a73086e18bb6c893779b6100c26

diff --git a/lib/jerboa/typed/checker.ss b/lib/jerboa/typed/checker.ss
index 2013f47..609252f 100644
--- a/lib/jerboa/typed/checker.ss
+++ b/lib/jerboa/typed/checker.ss
@@ -1916,6 +1916,19 @@
                  (list (cons 'inner-type type-arg))))
           errors))))
 
+  (def (infer-mutable-set-empty args env type-names expr)
+    (if (not (= (length args) 1))
+      (values #f (bad-constructor-arity expr 'mutable-set-empty 1 args))
+      (let* ([type-arg (strip-source-annotations (car args))]
+             [errors (check-type type-arg type-names)])
+        (values
+          (and (null? errors)
+               (make-typed-ir-call (list 'MutableSet type-arg)
+                 (expr-source expr) 'jvm-mutable-set-empty 'mutable-set-empty
+                 '()
+                 (list (cons 'inner-type type-arg))))
+          errors))))
+
   (def (infer-mutable-list-add args env type-names expr)
     (if (not (= (length args) 2))
       (values #f (bad-constructor-arity expr 'mutable-list-add! 2 args))
@@ -2659,6 +2672,8 @@
               (infer-pair args env type-names expr)]
              [(mutable-list-empty)
               (infer-mutable-list-empty args env type-names expr)]
+             [(mutable-set-empty)
+              (infer-mutable-set-empty args env type-names expr)]
              [(mutable-list-add!)
               (infer-mutable-list-add args env type-names expr)]
              [(mutable-set-add!)
diff --git a/lib/jerboa/typed/core.ss b/lib/jerboa/typed/core.ss
index 8cf146d..6fe364b 100644
--- a/lib/jerboa/typed/core.ss
+++ b/lib/jerboa/typed/core.ss
@@ -137,6 +137,7 @@
       jvm-list-ref
       jvm-map-ref-or-null
       jvm-set-contains
+      jvm-mutable-set-empty
       jvm-mutable-set-add
       jvm-mutable-list-empty
       jvm-mutable-list-add
diff --git a/lib/jerboa/typed/kotlin/lower.ss b/lib/jerboa/typed/kotlin/lower.ss
index e4a5f64..1eecd09 100644
--- a/lib/jerboa/typed/kotlin/lower.ss
+++ b/lib/jerboa/typed/kotlin/lower.ss
@@ -356,6 +356,12 @@
          (make-kt-index-get (car args) (cadr args))]
         [(jvm-set-contains)
          (make-kt-member-call (car args) 'contains (cdr args))]
+        [(jvm-mutable-set-empty)
+         (make-kt-new
+           (make-kt-type 'HashSet #f
+             (list (typed-type->kotlin-type
+                     (info-ref info 'inner-type 'Any))))
+           '())]
         [(jvm-mutable-set-add)
          (make-kt-block
            (list
diff --git a/tests/test-typed-checker.ss b/tests/test-typed-checker.ss
index 0f66d4d..3a79560 100644
--- a/tests/test-typed-checker.ss
+++ b/tests/test-typed-checker.ss
@@ -1061,6 +1061,14 @@
            (set-contains? ids id)))))
   '())
 
+(test "mutable-set empty returns a typed mutable set"
+  (error-kinds
+    '(typed-library (body mutable-set-empty-ok)
+       (export make-ids)
+       (def (make-ids) : (MutableSet String)
+         (mutable-set-empty String))))
+  '())
+
 (test "mutable-set add rejects wrong element type"
   (error-kinds
     '(typed-library (body mutable-set-wrong-element)
diff --git a/tests/test-typed-kotlin.ss b/tests/test-typed-kotlin.ss
index b51d8ed..6a90fe9 100644
--- a/tests/test-typed-kotlin.ss
+++ b/tests/test-typed-kotlin.ss
@@ -664,6 +664,8 @@
      (export seen? remember!)
      (def (seen? (ids : (Set String)) (id : String)) : Bool
        (set-contains? ids id))
+     (def (emptyIds) : (MutableSet String)
+       (mutable-set-empty String))
      (def (remember! (ids : (MutableSet String)) (id : String)) : Unit
        (mutable-set-add! ids id))))
 
@@ -678,6 +680,9 @@
 (test-contains "MutableSet type lowers to Kotlin generics"
   set-kotlin
   "fun remember_bang(ids: MutableSet<String>, id: String)")
+(test-contains "MutableSet empty lowers to typed HashSet"
+  set-kotlin
+  "return HashSet<String>()")
 (test-contains "MutableSet add lowers to Kotlin add"
   set-kotlin
   "ids.add(id)")