E-Ink News Daily

Back to list

Unexpected (to me) behaviour in Lisp sub-typing

Simon Dobson discovers unexpected behavior in SBCL's Common Lisp array sub-typing: when using constrained types like (unsigned-byte 16) in defstruct with short-vector syntax #nA(), type checking fails because the compiler assigns them the type simple-vector instead of simple-array. The issue stems from the compiler's optimization freedom, which treats short-vector literals as simple-vector without element-type information, breaking sub-type checks against parameterized array types.

Background

Common Lisp's type system is known for its expressiveness and complexity, with subtype relationships being a core feature used throughout the language. SBCL is a popular high-performance Common Lisp compiler that aggressively optimizes array storage based on declared element types.

Source
Lobsters
Published
Aug 15, 2026 at 12:08 AM
Score
5.0 / 10