keep the qualifiers written on a wildcard

(const _) parsed to a type variable, which had nowhere to keep the
const, so the type it was solved to came out without one -- for
(const _) and for the target of (* const _) alike.
This commit is contained in:
2026-10-16 17:04:20 +03:00
parent b52b2ffa07
commit 04122768b4
2 changed files with 27 additions and 14 deletions

View File

@@ -662,6 +662,15 @@ whitespace aside, THEN?"
"struct p* x = &s"))
(test-assert "a wildcard inside an array"
(emits? (in-fn "(var t [_ 3] #([int 3] : 1 2 3))") "int t[3]"))
;; a variable had nowhere to keep a qualifier written on it, and
;; what it was solved to came out without
(test-assert "a qualified wildcard keeps its qualifier"
(emits? (in-fn "(var k (const _) 5)") "const int k = 5"))
(test-assert "behind a pointer too"
(emits? (in-fn "(var p (* const _) (& a))") "const int * p = &a"))
(test-assert "and says it once, solved to a type already saying it"
(emits? (in-fn "(var k (const int) 1) (var p (* const _) (& k))")
"const int * p = &k"))
;; a compound literal carries its own type, where a brace
;; initializer has none and takes one from its context
(test-assert "a compound literal answers a bare wildcard"