decay an array into a wildcard standing alone

An array as a value is a pointer to its first element; _ took the array
type, and declared a copy that C cannot initialize from it.
This commit is contained in:
2026-10-18 22:02:55 +03:00
parent 60680bbb0a
commit 97b99ab842
3 changed files with 23 additions and 1 deletions

View File

@@ -687,6 +687,18 @@
"int * p = a + 1"))
(test-assert "while a length left to work out is not one"
(reports? (in-fn "(var t [_ _] #(1 2))") "cannot infer"))
;; an array as a value is a pointer to its first element, where `_'
;; declared a copy, which C cannot initialize from it
(test-assert "an array decays into `_'"
(emits? (in-fn "(var s [char 6]) (var t _ s)") "char * t = s"))
(test-assert "a row of one too"
(emits? (in-fn "(var m [int 2 3]) (var r _ [m 1])") "int * r = m[1]"))
(test-assert "and a field"
(emits? "(struct h ((xs [int 4]))) (fn f ((v (struct h))) void (var p _ (. v xs)))"
"int * p = v.xs"))
(test-assert "while a function is the pointer it already is"
(emits? "(fn g ((n int)) int (return n)) (fn f () void (var p _ g))"
"int (*p)(int) = g"))
;; 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"