diff --git a/src/core/specials.c b/src/core/specials.c index b3cea30a..3688eb72 100644 --- a/src/core/specials.c +++ b/src/core/specials.c @@ -251,6 +251,9 @@ static JanetTable *handleattr(JanetCompiler *c, int32_t argn, const Janet *argv) case JANET_STRING: janet_table_put(tab, janet_ckeywordv("doc"), attr); break; + case JANET_STRUCT: + janet_table_merge_struct(tab, janet_unwrap_struct(attr)); + break; } } return tab; diff --git a/test/suite0004.janet b/test/suite0004.janet index 208f7cc4..17b1f358 100644 --- a/test/suite0004.janet +++ b/test/suite0004.janet @@ -70,5 +70,17 @@ (assert (= ~(,defn 1 2 3) [defn 1 2 3]) "bracket tuples are never macros") (assert (= ~(,+ 1 2 3) [+ 1 2 3]) "bracket tuples are never function calls") +# Metadata + +(def foo-with-tags :a-tag :bar) +(assert (get (dyn 'foo-with-tags) :a-tag) "extra keywords in def are metadata tags") + +(def foo-with-meta {:baz :quux} :bar) +(assert (= :quux (get (dyn 'foo-with-meta) :baz)) "extra struct in def is metadata") + +(defn foo-fn-with-meta {:baz :quux} "This is a function" [x] (identity x)) +(assert (= :quux (get (dyn 'foo-fn-with-meta) :baz)) "extra struct in defn is metadata") +(assert (= "(foo-fn-with-meta x)\n\nThis is a function" (get (dyn 'foo-fn-with-meta) :doc)) "extra string in defn is docstring") + (end-suite)