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 207c239de6
commit 2345f7854e
3 changed files with 40 additions and 8 deletions

View File

@@ -885,6 +885,20 @@ whitespace aside, THEN?"
(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))())")))
;; c-struct/aux wrote the tag and the first `*' after it, and
;; dropped the rest of the chain
(test-group "a pointer chain to a struct"