Add typed Kotlin generic array type
ober
06442a897016857792d3ff87af5d08bfeb21eb78
--- a/lib/jerboa/typed/checker.ss +++ b/lib/jerboa/typed/checker.ss @@ -48,6 +48,7 @@ (def compound-type-arities '((List . 1) + (Array . 1) (Vector . 1) (MutableList . 1) (Map . 2) @@ -95,7 +96,7 @@ [(unknown-type) "Define the type in this typed-library, import it later when imports exist, or use a builtin type name."] [(unknown-type-constructor) - "Use a supported compound type constructor: List, Vector, MutableList, Map, Set, MutableSet, Nullable, Option, Result, Pair, Owned, Borrow, MutBorrow, or ->."] + "Use a supported compound type constructor: List, Array, Vector, MutableList, Map, Set, MutableSet, Nullable, Option, Result, Pair, Owned, Borrow, MutBorrow, or ->."] [(bad-type-arity) "Check the number of type arguments for the compound type."] [(duplicate-type duplicate-value duplicate-field duplicate-param --- a/lib/jerboa/typed/kotlin/lower.ss +++ b/lib/jerboa/typed/kotlin/lower.ss @@ -97,6 +97,8 @@ [else (make-kt-type type #f '())])] [(and (pair? type) (eq? (car type) 'List)) (make-kt-type 'List #f (list (typed-type->kotlin-type (cadr type))))] + [(and (pair? type) (eq? (car type) 'Array)) + (make-kt-type 'Array #f (list (typed-type->kotlin-type (cadr type))))] [(and (pair? type) (eq? (car type) 'Vector)) (make-kt-type 'List #f (list (typed-type->kotlin-type (cadr type))))] [(and (pair? type) (eq? (car type) 'MutableList)) --- a/tests/test-typed-kotlin.ss +++ b/tests/test-typed-kotlin.ss @@ -716,6 +716,21 @@ (test-contains "IntArray length lowers to Kotlin size" array-kotlin "return items.size") +(define generic-array-form + '(typed-library (sample typed genericarray) + (export sameCertificates) + (type X509Certificate) + (def (sameCertificates + (items : (Array X509Certificate))) : (Array X509Certificate) + items))) + +(define generic-array-kotlin + (typed-library-form->kotlin-string generic-array-form)) + +(test-contains "generic Array type lowers to Kotlin Array" + generic-array-kotlin + "fun sameCertificates(items: Array<X509Certificate>): Array<X509Certificate>") + (define array-set-form '(typed-library (sample typed arrayset) (export setGray setEdge setWeight)