Allow typed Kotlin array size and indexing
ober
035ee76dd63f2402a3cd9501d4485e081c66dbb3
--- a/lib/jerboa/typed/checker.ss +++ b/lib/jerboa/typed/checker.ss @@ -1972,7 +1972,7 @@ (def (list-like-inner-type type) (and (pair? type) - (memq (car type) '(List Vector MutableList)) + (memq (car type) '(List Array Vector MutableList)) (cadr type))) (def (infer-list-size args env type-names expr) @@ -1986,7 +1986,7 @@ (if inner-type '() (list (make-check-error 'argument-type-mismatch - "list-size expects a List, Vector, or MutableList value" + "list-size expects a List, Array, Vector, or MutableList value" expr (expr-source (car args)))))] [ok? (and list-ir (null? errors) (null? type-errors))]) @@ -2012,7 +2012,7 @@ (list (make-check-error 'argument-type-mismatch - "list-ref expects a List, Vector, or MutableList value" + "list-ref expects a List, Array, Vector, or MutableList value" expr (and (pair? args) (expr-source (car args)))))) (if (eq? index-type 'Int32) --- a/tests/test-typed-kotlin.ss +++ b/tests/test-typed-kotlin.ss @@ -746,11 +746,18 @@ (define generic-array-form '(typed-library (sample typed genericarray) - (export sameCertificates) + (export sameCertificates certificateCount firstCertificate) + (type Int32) (type X509Certificate) (def (sameCertificates (items : (Array X509Certificate))) : (Array X509Certificate) - items))) + items) + (def (certificateCount + (items : (Array X509Certificate))) : Int32 + (list-size items)) + (def (firstCertificate + (items : (Array X509Certificate))) : X509Certificate + (list-ref items (int32 0))))) (define generic-array-kotlin (typed-library-form->kotlin-string generic-array-form)) @@ -758,6 +765,12 @@ (test-contains "generic Array type lowers to Kotlin Array" generic-array-kotlin "fun sameCertificates(items: Array<X509Certificate>): Array<X509Certificate>") +(test-contains "generic Array size lowers to Kotlin size" + generic-array-kotlin + "return items.size") +(test-contains "generic Array ref lowers to Kotlin indexed access" + generic-array-kotlin + "return items[0]") (define array-set-form '(typed-library (sample typed arrayset)