Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 88ba7fd

Browse files
committedMay 27, 2024
Better handle coord meta elision for (), '() and 'foo
1 parent e941221 commit 88ba7fd

File tree

3 files changed

+35
-32
lines changed

3 files changed

+35
-32
lines changed
 

‎CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# Changelog
22

33
## master (unreleased)
4-
4+
55
### New Features
66

77
### Changes
88

99
### Bugs fixed
1010

11+
- Don't tag ()
12+
- After eliding meta (reader and coord) leave nil instead of {} when that was the only meta
13+
- Refactor Utils.mergeMeta
14+
1115
## 1.12.0-alpha11 (unreleased)
1216

1317
### New Features

‎src/jvm/clojure/lang/Compiler.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,11 @@ static public Object getCompilerOption(Keyword k){
303303
static Object elideMeta(Object m){
304304
Collection<Object> elides = (Collection<Object>) getCompilerOption(elideMetaKey);
305305

306-
// Always elide Storm coordinates meta
306+
// Always elide Storm coordinates meta, and if storm coordinates where the only thing
307+
// added leave meta as null. If not we are going to endup with an empty map as meta
308+
// that wasn't there in the first place
307309
m = RT.dissoc(m, LispReader.COORD_KEY);
310+
if (RT.count(m) == 0) m = null;
308311

309312
if(elides != null)
310313
{

‎src/jvm/clojure/storm/Utils.java

+26-30
Original file line numberDiff line numberDiff line change
@@ -34,37 +34,31 @@
3434
public class Utils {
3535

3636
public static Object mergeMeta(Object x, IPersistentMap m) {
37-
if (x instanceof clojure.lang.IObj) {
37+
if (x instanceof clojure.lang.IObj && RT.count(m) > 0) {
38+
// if x supports meta and there is meta to merge
3839
IObj o = (IObj) x;
39-
if (m != null || RT.meta(o) != null)
40-
{ // if there is meta in any of the args
41-
IPersistentMap retMeta = PersistentHashMap.EMPTY;
42-
IPersistentMap oMeta = RT.meta(o);
4340

44-
if (oMeta != null)
45-
{
46-
for (Object meo : oMeta)
47-
{
48-
MapEntry me = (MapEntry) meo;
49-
retMeta = retMeta.assoc(me.getKey(), me.getValue());
50-
}
51-
}
52-
// m meta overrides the input Object meta when both have
53-
if (m != null)
54-
{
55-
for (Object meo : m)
56-
{
57-
MapEntry me = (MapEntry) meo;
58-
retMeta = retMeta.assoc(me.getKey(), me.getValue());
59-
}
60-
}
61-
return o.withMeta(retMeta);
62-
} else {
63-
return x;
64-
}
65-
}
66-
return x;
67-
}
41+
IPersistentMap retMeta = PersistentHashMap.EMPTY;
42+
IPersistentMap oMeta = RT.meta(o);
43+
44+
if (oMeta != null) {
45+
for (Object meo : oMeta) {
46+
MapEntry me = (MapEntry) meo;
47+
retMeta = retMeta.assoc(me.getKey(), me.getValue());
48+
}
49+
}
50+
51+
// m meta overrides the input Object meta when both have
52+
for (Object meo : m) {
53+
MapEntry me = (MapEntry) meo;
54+
retMeta = retMeta.assoc(me.getKey(), me.getValue());
55+
}
56+
57+
return o.withMeta(retMeta);
58+
} else {
59+
return x;
60+
}
61+
}
6862

6963
public static Symbol maybeGetTraceSymbol(Symbol sym, ISeq form){
7064
// If the form is the expansion of a defmethod we use the symbol of
@@ -219,7 +213,9 @@ public static Object tagFormRecursively(Object form) {
219213
PersistentVector.EMPTY,
220214
new AFn() {
221215
public Object invoke(Object coord, Object frm) {
222-
if ((frm instanceof clojure.lang.ISeq) || (frm instanceof clojure.lang.Symbol))
216+
// Tag seqs and symbols but don't tag empty lists
217+
if (((frm instanceof clojure.lang.ISeq) && RT.count(frm) > 0) ||
218+
(frm instanceof clojure.lang.Symbol))
223219
return addCoordMeta(frm, (IPersistentVector)coord);
224220
else
225221
return frm;

0 commit comments

Comments
 (0)
Please sign in to comment.