diff --git a/fmt-c-writer.scm b/fmt-c-writer.scm index 35be1509..dec4d6ed 100644 --- a/fmt-c-writer.scm +++ b/fmt-c-writer.scm @@ -315,7 +315,7 @@ forms, and what remains." (match form (('¤ . array-type) (if (array-bound? form) - `(%array ,(walk-type (array-element-type form)) ,(last array-type)) + `(%array ,(walk-type (array-element-type form)) ,(walk-expr (last array-type))) ;; sugar for pointer... Do we really need it? Guess why not, ;; it's a strong semantic cue `(%array ,(walk-type (array-element-type form))))) diff --git a/tests/codegen.scm b/tests/codegen.scm index 2a1edd3b..67d7fb1e 100644 --- a/tests/codegen.scm +++ b/tests/codegen.scm @@ -678,6 +678,11 @@ compiles." (emits? "(define N 4) (struct s ((a (¤ char (* 2 N)))))" "char a[2 * N]")) (test-assert "an integer bound still works" (emits? "(struct s ((a (¤ int 4))))" "int a[4]")) + ;; ...and it is spelled the way the same name is in an expression + (test-assert "a bound's name is converted" + (emits? (in-fn "(var xs (¤ u16 CHUNK-AREA))") "u16 xs[CHUNK_AREA]")) + (test-assert "so is one inside an expression bound" + (emits? (in-fn "(var xs (¤ u16 (* 2 CHUNK-AREA)))") "u16 xs[2 * CHUNK_AREA]")) ;; a multi-word type is keywords all the way down, so a trailing ;; keyword belongs to the type and leaves the array unsized (test-assert "a multi-word type is not a bound"