Skip to content

Commit 7ea5086

Browse files
committed
class survives reloading
1 parent 93850a3 commit 7ea5086

4 files changed

Lines changed: 21 additions & 11 deletions

File tree

src/sci/impl/deftype.cljc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
(write-all w (clojure-str this))))])
8080

8181
types/IBox
82-
(getVal [_] ext-map))
82+
(getVal [_] ext-map)
83+
(setVal [_ _]))
8384

8485
(defn ->type-impl [rec-name type var m]
8586
(SciType. rec-name type var m))

src/sci/impl/namespaces.cljc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,12 @@
797797
;;;; Record impl
798798

799799
(defn -create-type [data]
800-
(new sci.lang.Type data nil nil))
800+
(let [t (new sci.lang.Type data nil nil)
801+
ctx (store/get-ctx)
802+
t-name (:sci.impl/type-name data)
803+
env (:env ctx)]
804+
(swap! env assoc-in [:types t-name] t)
805+
t))
801806

802807
#_(defn -reg-key! [rec-type k v]
803808
(when (instance? sci.lang.Type rec-type)

src/sci/impl/records.cljc

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,16 @@
349349
A protocol is represented by a map with :ns, :methods and optionally :class. This is also an implementation detail."
350350
;; TODO: we should probably use munging here for namespaces with hyphens in them.
351351
([ctx sym]
352-
(let [sym-str (str sym)
353-
last-dot (str/last-index-of sym-str ".")
354-
class-name (if last-dot
355-
(subs sym-str (inc last-dot) (count sym-str))
356-
sym-str)
357-
namespace (if last-dot
358-
(symbol (subs sym-str 0 last-dot))
359-
(utils/current-ns-name))]
360-
(resolve-record-or-protocol-class ctx namespace (symbol class-name))))
352+
(or (some-> ctx :env deref :types (get sym))
353+
(let [sym-str (str sym)
354+
last-dot (str/last-index-of sym-str ".")
355+
class-name (if last-dot
356+
(subs sym-str (inc last-dot) (count sym-str))
357+
sym-str)
358+
namespace (if last-dot
359+
(symbol (subs sym-str 0 last-dot))
360+
(utils/current-ns-name))]
361+
(resolve-record-or-protocol-class ctx namespace (symbol class-name)))))
361362
([ctx package class]
362363
(let [namespace (-> package str (str/replace "_" "-") symbol)]
363364
(when-let [sci-var (let [ns (get-in @(:env ctx) [:namespaces namespace])]

test/sci/namespaces_test.cljc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,6 @@ bar/bar"}
382382
(when (= 'foo.bar namespace)
383383
{:source "(ns foo.bar) (def x :success)"
384384
:file "foo/bar.clj"}))})))))
385+
386+
(deftest class-survives-remove-ns-test
387+
(is (true? (sci/eval-string "(ns foo) (deftype Dude []) (ns dude) (remove-ns 'foo) (some? foo.Dude)"))))

0 commit comments

Comments
 (0)