Allow mutable lists where typed lists are expected
ober
3c4bedd1ae46a385df7ee25f576f55ed448586c1
--- a/lib/jerboa/typed/checker.ss +++ b/lib/jerboa/typed/checker.ss @@ -341,6 +341,11 @@ (eq? (car actual) 'MutableSet) (eq? (car expected) 'Set) (type-assignable? (cadr actual) (cadr expected))) + (and (pair? actual) + (pair? expected) + (eq? (car actual) 'MutableList) + (eq? (car expected) 'List) + (type-assignable? (cadr actual) (cadr expected))) (owned-to-borrow-assignable? actual expected))) (def (owned-type? type) --- a/tests/test-typed-checker.ss +++ b/tests/test-typed-checker.ss @@ -1099,6 +1099,17 @@ (seen? ids id)))) '()) +(test "mutable-list is assignable to list parameter" + (error-kinds + '(typed-library (body mutable-list-assignable) + (export count-through-list) + (type Int32) + (def (count (items : (List String))) : Int32 + (list-size items)) + (def (count-through-list (items : (MutableList String))) : Int32 + (count items)))) + '()) + (test "set-contains rejects wrong element type" (error-kinds '(typed-library (body set-contains-wrong-element)