From 415c842af16e3c1573325994bd02b8bac1e5d91c Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Sat, 25 Sep 2021 12:27:40 -0500 Subject: [PATCH] Move dispatch for unions into the kwargs --- src/clj/coffi/ffi.clj | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/clj/coffi/ffi.clj b/src/clj/coffi/ffi.clj index a81583e..e964497 100644 --- a/src/clj/coffi/ffi.clj +++ b/src/clj/coffi/ffi.clj @@ -495,13 +495,17 @@ ;;; Union types (defmethod c-layout ::union - [[_union _dispatch types & {:as _opts} :as _type]] + [[_union types & {:as _opts} :as _type]] (let [items (map c-layout types)] (MemoryLayout/unionLayout (into-array MemoryLayout items)))) (defmethod serialize-into ::union - [obj [_union dispatch _types & {:keys [extract]}] segment scope] + [obj [_union _types & {:keys [dispatch extract]} :as type] segment scope] + (when-not dispatch + (throw (ex-info "Attempted to serialize a union with no dispatch function" + {:type type + :value obj}))) (let [type (dispatch obj)] (serialize-into (if extract