Afternoon. Does anyone know why a defrecord fails when implementing a protocol from another ns but not when one implementing one from its own ns?
$ nbb -v
nbb v1.2.179
$ nbb -e '(ns storage) (defprotocol IStorage (-store [_ foo])) (ns user [:require [storage]]) (defrecord Storage [] storage/IStorage (-store [_ foo] (prn :foo foo))) (-store (->Storage) :hoo)'
----- Error --------------------------------------
Message: Could not resolve symbol: -store
Location: 1:157
Phase: analysis
----- Stack trace --------------------------------
user - <expr>:1:157
Could not resolve symbol: -store
$ nbb -e '(defprotocol IStorage (-store [_ foo])) (defrecord Storage [] IStorage (-store [_ foo] (prn :foo foo))) (-store (->Storage) :hoo)'
:foo :hoo
Asking about this because I’m trying to run https://github.com/logseq/datascript/blob/51fe8d3fc95056bb82553b3803e5994d194206b4/test/datascript/test/storage.cljs#L11-L13 through nbb’s sci and it also fails to resolve the protocol’s method nameThe issue is not the protocol extension, but your call at the end, this should be:
(storage/-store (->Storage) :hoo)protocol functions/vars aren't automatically referred or so
Ah yep. Thanks. My mistake in trying to make the smallest repro. The original bug I’m seeing isn’t able to load the defprotocol:
bb test [16:34:51]
Running datascript tests...
----- Error --------------------------------------
Message: Could not resolve symbol: -store
Location: /Users/me/code/work/nbb-features/test/libraries/datascript/test/datascript/test/storage.cljs:11:1
Phase: analysis
----- Context ------------------------------------
7: [datascript.core :as d]
8: [datascript.storage :as storage]
9: #_[datascript.test.core :as tdc]))
10:
11: (defrecord Storage [*disk *reads *writes *deletes]
^--- Could not resolve symbol: -store
12: storage/IStorage
13: (-store [_ addr+data-seq]
14: (doseq [[addr data] addr+data-seq]
15: (vswap! *disk assoc addr (pr-str data))
16: (vswap! *writes conj addr)))
Could not resolve symbol: -store
Error while executing task: test
This is in the context of running datascript tests through a custom nbb in nbb-featuresmaybe you can make another repro?
Sure. I’ll open up a sci issue with full repro. I thought I’d sanity check ask before doing so but it sounds like this should work
ok make a tiny repro that works 100% in CLJ(s) and not in SCI and I'll have a look tomorrow
Sure. Thanks