read an array's length as types does

Inference took only an integer for a length, and read a name there as
part of the element type: [_ N] did not solve, and an array of [int N]
decayed to int N *.
This commit is contained in:
2026-10-18 22:02:55 +03:00
parent b744fb2e31
commit 755a733252
2 changed files with 21 additions and 11 deletions

View File

@@ -735,6 +735,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]"))
;; only an integer was taken for a length; a name was read as part
;; of the element's
(test-assert "of a named length"
(emits? "(define N 3) (fn f () void (var t [_ N] #(1 2 3)))" "int t[N]"))
(test-assert "which an array of decays from as any other"
(emits? "(define N 3) (fn f () void (var a [int N]) (var p _ (+ a 1)))"
"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"))
;; 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"