From 556edc9f0d8159bc6a485e60842b2e9f75101f55 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Thu, 27 Aug 2020 07:46:00 -0500 Subject: [PATCH] Fix import macro to not coerce everything to string. --- CHANGELOG.md | 1 + src/boot/boot.janet | 3 ++- test/suite0010.janet | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a41ed2b..dbb148a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ All notable changes to this project will be documented in this file. ## Unreleased - ??? +- Fix import macro to not try and coerce everything to a string. - Allow passing a second argument to `disasm`. - Add `cancel`. Resumes a fiber but makes it immediately error at the yield point. - Allow multi-line paste into built in repl. diff --git a/src/boot/boot.janet b/src/boot/boot.janet index e6f0fcf0..4a465207 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -2475,7 +2475,8 @@ to be called. Dynamic bindings will NOT be imported. Use :fresh to bypass the module cache." [path & args] - (def argm (map |(if (keyword? $) $ (string $)) args)) + (def ps (partition 2 args)) + (def argm (mapcat (fn [[k v]] [k (if (= k :as) (string v) v)]) ps)) (tuple import* (string path) ;argm)) (defmacro use diff --git a/test/suite0010.janet b/test/suite0010.janet index 1205d192..62ef3bab 100644 --- a/test/suite0010.janet +++ b/test/suite0010.janet @@ -57,4 +57,8 @@ (assert (= nil (curenv 1000000)) "curenv 3") (assert (= root-env (curenv 1)) "curenv 4") +# Import macro test +(assert-no-error "import macro 1" (macex '(import a :as b :fresh maybe))) +(assert (deep= ~(,import* "a" :as "b" :fresh maybe) (macex '(import a :as b :fresh maybe))) "import macro 2") + (end-suite)