flan/test/programs/pkg-return.flan
Joseph Ferano 2e203f64b8 bytes copies, bytes-view aliases, and a dev-session segfault parks
The INSERTIONSORT crash, all three rulings (FIX.org 2026-09-20):

- (bytes s) allocates a writable copy through the allocator surface —
  context or (bytes s a), StorageExhausted with retry, a registry note in
  dev builds (flan_bytes_dup, lowered like vec-new). (bytes-view s) is the
  old zero-cost reinterpret, renamed, read-only by convention; every
  in-repo reader swept over to it. (string b) unchanged.
- String constants were already read-only on both backends at -O0; now
  pinned — bytes-copy.flan rows on LLVM/-O0/--x86, and dies_segv rows
  asserting the write-through-view trap on both backends.
- A dev build installs a SIGSEGV/SIGBUS handler by the same dev-only
  constructor slot that arms the registry: one line naming the address and
  the innermost frame, then the trap-hook park — stopped, not dead, the
  daemon serving. No agent: message and re-raise. Release builds untouched.
  Pinned by trap_park over dev-segv.flan.
2026-09-20 23:12:42 +07:00

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 [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)