Skip to content

Commit fd0477a

Browse files
authored
[Fix #45] def-transfer: emit correct :tag metadata (#46)
Reoccurrences are prevented by introducing Eastwood as a linter, which detected this issue in the first place.
1 parent 4066d63 commit fd0477a

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ jobs:
5252
# run tests!
5353
- run: lein with-profile ci do clean, test
5454

55+
- run: lein eastwood
56+
5557
deploy:
5658
docker:
5759
# specify the version you desire here

project.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
:test-selectors {:stress :stress
2222
:default (complement :stress)}
2323
:plugins [[lein-codox "0.10.3"]
24+
[jonase/eastwood "0.4.3"]
2425
[lein-jammin "0.1.1"]
2526
[ztellman/lein-cljfmt "0.1.10"]]
2627
:cljfmt {:indents {#".*" [[:inner 0]]}}

src/byte_streams.clj

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,22 @@
102102
:else
103103
(g/type (eval x))))
104104

105+
(defn- tag-metadata-for [^Type src]
106+
(if (and (instance? Class (.type src))
107+
(not (.wrapper src)))
108+
{:tag (if (= src (normalize-type-descriptor 'bytes))
109+
'bytes
110+
(.getName ^Class (.type src)))}
111+
{}))
112+
105113
(defmacro def-conversion
106114
"Defines a conversion from one type to another."
107115
[[src dst :as conversion] params & body]
108116
(let [^Type src (normalize-type-descriptor src)
109117
dst (normalize-type-descriptor dst)]
110118
`(let [f#
111119
(fn [~(with-meta (first params)
112-
{:tag (when (and (instance? Class (.type src)) (not (.wrapper src)))
113-
(if (= src (normalize-type-descriptor 'bytes))
114-
'bytes
115-
(.getName ^Class (.type src))))})
120+
(tag-metadata-for src))
116121
~(if-let [options (second params)]
117122
options
118123
`_#)]
@@ -127,10 +132,12 @@
127132
"Defines a byte transfer from one type to another."
128133
[[src dst] params & body]
129134
(let [src (normalize-type-descriptor src)
130-
dst (normalize-type-descriptor dst)]
135+
dst (normalize-type-descriptor dst)
136+
src-meta (tag-metadata-for src)
137+
dst-meta (tag-metadata-for dst)]
131138
`(swap! src->dst->transfer assoc-in [~src ~dst]
132-
(fn [~(with-meta (first params) {:tag src})
133-
~(with-meta (second params) {:tag dst})
139+
(fn [~(with-meta (first params) src-meta)
140+
~(with-meta (second params) dst-meta)
134141
~(if-let [options (get params 2)] options (gensym "options"))]
135142
~@body))))
136143

src/byte_streams/utils.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
[[x it] & body]
2727
(let [it-sym (gensym "iterable")]
2828
`(let [~it-sym ~it
29-
it# (.iterator ~(with-meta it-sym {:tag "Iterable"}))]
29+
it# (.iterator ~(with-meta it-sym {:tag 'java.lang.Iterable}))]
3030
(loop []
3131
(when (.hasNext it#)
3232
(let [~x (.next it#)]

test/byte_streams_test.clj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
(ns byte-streams-test
2-
(:use
3-
[byte-streams])
42
(:require
3+
[byte-streams :refer [bytes= compare-bytes conversion-path convert dev-null possible-conversions seq-of stream-of to-byte-array to-byte-buffer to-byte-buffers to-input-stream to-string transfer vector-of]]
54
[clojure.test :refer :all]
65
[byte-streams.char-sequence :as cs])
76
(:refer-clojure

0 commit comments

Comments
 (0)