diff --git a/semen.scm b/semen.scm index 8902d0cf..5d53e729 100644 --- a/semen.scm +++ b/semen.scm @@ -715,7 +715,12 @@ (convert-to-closure type arg env form) (let ((given (expression-type arg env))) (cond - ((brace-initializer? arg) arg) + ((brace-initializer? arg) + (let ((held (array-length type))) + (when (and held (not (= held (length (remove comment-form? + (vector->list arg)))))) + (sex-error form "array is not as long as its field" (first field)))) + arg) ((not (array-form? given)) (sex-error form "an array field takes an array" (first field))) ((not (eqv? (array-length given) (array-length type))) diff --git a/tests/encapsulation.scm b/tests/encapsulation.scm index 58c8498e..95d553eb 100644 --- a/tests/encapsulation.scm +++ b/tests/encapsulation.scm @@ -228,6 +228,12 @@ (test-assert "and as many as the field holds" (reports? "(sum t ((a ((xs [int 2])))))(fn f () t (var v [int 3] #(1 2 3)) (return (t/a v)))" "array is not as long as its field")) + (test-assert "and so must a literal" + (reports? "(sum t ((a ((xs [int 2])))))(fn f () t (return (t/a #(1 2 3))))" + "array is not as long as its field")) + (test-assert "not filling it with zeros either" + (reports? "(sum t ((a ((xs [int 2])))))(fn f () t (return (t/a #(1))))" + "array is not as long as its field")) (test-assert "an array field takes an array" (reports? "(sum t ((a ((xs [int 2])))))(fn f () t (var p (* int) 0) (return (t/a p)))" "an array field takes an array"))