Add macro expansion in defclass

This commit is contained in:
Nathan Woodrow 2014-12-07 11:51:01 +10:00
parent c5e2fd955f
commit 41806895b2
3 changed files with 11 additions and 0 deletions

View File

@ -54,3 +54,4 @@
* Ed Singleton <singletoned@gmail.com>
* Kevin Yap <me@kevinyap.ca>
* Matthías Páll Gissurarson <mpg@mpg.is>
* Nathan Woodrow <woodrow.nathan@gmail.com>

View File

@ -2006,6 +2006,8 @@ class HyASTCompiler(object):
expression,
"Wrong argument type for defclass attributes definition.")
for b in body_expression:
if isinstance(b, HyExpression):
b = macroexpand(b, self.module_name)
if len(b) != 2:
raise HyTypeError(
expression,

View File

@ -83,3 +83,11 @@
(assert (= mL.x 1))
(assert (in "begin" mL.__doc__))
(assert (in "end" mL.__doc__)))
(defn test-defclass-macroexpand []
"NATIVE: test defclass with macro expand"
(defmacro M [] `[x (fn [self x] (setv self._x x))])
(defclass A [] [(M)])
(setv a (A))
(a.x 1)
(assert (= a._x 1)))