write a typedef's target as a type

It fell through to the expression walk, which read (* const char) as a
dereference and an array as a subscript, and died on a fn type.

Fixes #53.
This commit is contained in:
2026-10-09 15:58:01 +03:00
parent 9a490a942c
commit 8774400f1f
3 changed files with 27 additions and 1 deletions

View File

@@ -693,6 +693,19 @@ compiles."
(test-assert "nor one behind a pointer"
(emits? "(struct t ((z int))) (struct s ((a (¤ * struct t))))" "struct t* a[]")))
;; A typedef's target is a type, and was walked as an expression: a
;; pointer read as a dereference, an array as a subscript
(test-group "typedefs"
(test-assert "of a name"
(emits? "(typedef small int)" "typedef int small;"))
(test-assert "of a pointer"
(emits? "(typedef cstr (* const char))" "typedef const char * cstr;"))
(test-assert "of an array"
(emits? "(typedef vec4 (¤ float 4))" "typedef float vec4[4];"))
(test-assert "of a function pointer"
(emits? "(typedef colour-fn (fn ((i32)) u32))"
"typedef u32 (*colour_fn)(i32);")))
;; `.' is C's `.' or its `->' depending on what is being read from,
;; so a path reads the same however the thing it starts from is held
(test-group "member access"