Skip to content

Commit c241328

Browse files
pfeodrippejpmonettas
authored andcommitted
Fix incorrect type hint compiler setting (divergent with upstream clojure)
```clojure ;;clj - works ;;flowstorm - error (-> (Component/newBuilder) (.setMyView ^MyView$Builder (-> (MyView/newBuilder) .build)) .build) ``` ```clojure ;;clj - error ;;flowstorm - error (-> (Component/newBuilder) (.setMyView ^MyView$Builder (.build (MyView/newBuilder))) .build)) ```
1 parent 80933a1 commit c241328

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

src/jvm/clojure/storm/Utils.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import java.util.regex.Pattern;
3636

3737
public class Utils {
38+
39+
private static final Keyword TAG_KEY = Keyword.intern(null, "tag");
3840

3941
public static Object mergeMeta(Object x, IPersistentMap m) {
4042
if (x instanceof clojure.lang.IObj && RT.count(m) > 0) {
@@ -54,7 +56,9 @@ public static Object mergeMeta(Object x, IPersistentMap m) {
5456
// m meta overrides the input Object meta when both have
5557
for (Object meo : m) {
5658
IMapEntry me = (IMapEntry) meo;
57-
retMeta = retMeta.assoc(me.key(), me.val());
59+
if (!TAG_KEY.equals(me.key())) {
60+
retMeta = retMeta.assoc(me.key(), me.val());
61+
}
5862
}
5963

6064
return o.withMeta(retMeta);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(ns clojure.test-clojure.storm-typehint-bug
2+
(:require
3+
[clojure.test :refer [deftest is testing]])
4+
(:import (clojure.testfixtures Component MyView MyView$Builder)))
5+
6+
(def form-1
7+
"Returns a function that executes the inline .build call (previously failing)."
8+
(fn []
9+
(-> (Component/newBuilder)
10+
(.setMyView ^MyView$Builder
11+
(.build (MyView/newBuilder)))
12+
.build)))
13+
14+
(def form-2
15+
"Returns a function that executes the threaded -> form (was expected to succeed)."
16+
(fn []
17+
(-> (Component/newBuilder)
18+
(.setMyView ^MyView$Builder
19+
(-> (MyView/newBuilder)
20+
.build))
21+
.build)))
22+
23+
(deftest wrong-type-hint-falls-back-to-reflection-test
24+
(testing "Flow-Storm instrumentation matches Clojure's fallback for incorrect hints"
25+
(is (thrown? java.lang.ClassCastException (form-1)))
26+
(is (some? (form-2)))))
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package clojure.testfixtures;
2+
3+
public class Component {
4+
5+
private final MyView view;
6+
7+
private Component(MyView view) {
8+
this.view = view;
9+
}
10+
11+
public MyView getMyView() {
12+
return view;
13+
}
14+
15+
public static Builder newBuilder() {
16+
return new Builder();
17+
}
18+
19+
public static final class Builder {
20+
private MyView view;
21+
22+
public Builder setMyView(MyView.Builder builder) {
23+
this.view = builder == null ? null : builder.build();
24+
return this;
25+
}
26+
27+
public Builder setMyView(MyView view) {
28+
this.view = view;
29+
return this;
30+
}
31+
32+
public Component build() {
33+
return new Component(view);
34+
}
35+
}
36+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package clojure.testfixtures;
2+
3+
public class MyView {
4+
5+
private final String id;
6+
7+
private MyView(String id) {
8+
this.id = id;
9+
}
10+
11+
public String id() {
12+
return id;
13+
}
14+
15+
public static Builder newBuilder() {
16+
return new Builder();
17+
}
18+
19+
public static final class Builder {
20+
private String id = "";
21+
22+
public Builder withId(String id) {
23+
this.id = id;
24+
return this;
25+
}
26+
27+
public MyView build() {
28+
return new MyView(id);
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)