nest a function type's declarator round the name

A function type's return was written ahead of its declarator, so one
returning a function pointer came out int (*)(int) get (void), and a
variable of such a type as void (*)() (*g)(int).
This commit is contained in:
2026-10-18 22:02:55 +03:00
parent 4e71d327f5
commit 18962f43ad
3 changed files with 40 additions and 8 deletions

View File

@@ -828,6 +828,20 @@
(test-assert "behind as many stars as are written"
(emits? "(struct h ((f (* * (struct ((c int)))))))" "} * * f;")))
;; A function type's return was written ahead of its declarator, so a
;; function returning one came out `int (*)(int) get (void)'
(test-group "a function type returning one"
(test-assert "a function returning a function pointer"
(emits? "(fn inc ((x int)) int (return x)) (fn get () (fn ((int)) int) (return inc))"
"int (*get (void))(int)"))
(test-assert "and its prototype"
(emits? "(pub fn get () (fn ((int)) int))" "int (*get (void))(int);"))
(test-assert "a variable of one"
(emits? "(var g (fn ((int)) (fn () void)))" "void (*(*g)(int))()"))
(test-assert "and a parameter"
(emits? "(fn take ((f (fn ((int)) (fn () void)))) void (return))"
"take (void (*(*f)(int))())")))
;; Operands past what an operator takes were written as they came:
;; (< a b c) as C's own chain, which compares a boolean with c
(test-group "operator arity"