Closed
Description
Hi,
When trying to unquote a deftype
defined in namespace B from namespace A in a macro, the following error occurs:
NameError: name 'TypeOther' is not defined
To reproduce
- Create an
other.lpy
file defining a new type
other.lpy
(ns other)
(deftype TypeOther []
(__repr__ [this] "a"))
(TypeOther.)
- Create an
issue.lpy
file that uses the type in a macro
(ns issue
(:require other)
(:import other))
(println :type-other (other/TypeOther))
(defmacro issue []
`(identity ~(other/TypeOther)))
(println :issue (issue))
- on the REPL, import the
issue
namespace, the above error is thrown
basilisp.user=> (require 'issue)
:type-other a
Traceback (most recent call last):
...
File "C:\src\basilisp\src\issue.lpy", line 10, in <module>
(println :issue (issue))
^^^^^^^
NameError: name 'TypeOther' is not defined
The same works in Clojure
other.clj
(ns other)
(deftype TypeOther []
Object
(toString [this] "a"))
issue.clj
(ns issue
(:require other)
(:import [other TypeOther]))
(defmacro issue []
`(identity ~(TypeOther.)))
(println :issue (issue))
user=> (require 'issue)
:issue #object[other.TypeOther 0x3b64ccce a]
nil
Note that to reference the deftype in Clojure, the other namespace must be both :require
d and the type explicitly :importe
d.
Encountered while trying to port the hiccup lib to Basilisp for fun in case you are wondering where the latest corner cases are coming from 😅. It goes well so far (praise to your hard work maintaining compatibility with Clojure 🙌), I can compile the lib fine, I'm currently running through the tests. Thanks for the latest fixes.