flan/test/programs/pkg-return.flan

28 lines
1.1 KiB
Plaintext

;;;; A package-qualified struct in return position.
;;;;
;;;; The parser decides "is this form a return type or the first body form?"
;;;; from the set of type names the file declares — and an import is resolved
;;;; after parsing, so a package's structs cannot be in that set. The result
;;;; was that (defn mk [] rl/Vector2 ...) read the return type as the body and
;;;; failed with "unknown name rl/Vector2", which named the symptom and not the
;;;; cause. The alias plus the capital is the signal: a bare capitalised symbol
;;;; is never a value here, since a constructor is (Name {...}) and an enum
;;;; member is a keyword.
(import edn "vendor:edn")
(defstruct Local [n i32])
;;; The case that used to fail: a package struct as the declared return type.
(defn fresh [src [const u8]] edn/Cursor (edn/cursor src))
;;; And the one that must keep working: a lowercase qualified name in the same
;;; position is an expression, not a type.
(defn local [] Local (Local {.n 5}))
(defn main [] i32
(let [c (fresh (bytes-view "[1 2]"))
t (edn/next (addr c))]
(print (.kind t)) (println ""))
(print (.n (local))) (println "")
0)