Visitar URL original
fix: field overload method value should not reflect · clojure/clojure@0c0dbae · GitHub
Skip to content

Commit 0c0dbae

Browse files
bronsapuredanger
authored andcommitted
fix: field overload method value should not reflect
Signed-off-by: Alex Miller <alex.miller@cognitect.com>
1 parent 7a2b1fb commit 0c0dbae

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ public QualifiedMethodExpr(Class methodClass, Symbol sym) {
11881188
public QualifiedMethodExpr(Class methodClass, Symbol sym, StaticFieldExpr fieldOL) {
11891189
c = methodClass;
11901190
methodSymbol = sym;
1191-
tagClass = tagOf(sym) != null ? HostExpr.tagToClass(tagOf(sym)) : AFn.class;
1191+
tagClass = tagOf(sym) != null ? HostExpr.tagToClass(tagOf(sym)) : null;
11921192
hintedSig = tagsToClasses(paramTagsOf(sym));
11931193
if(sym.name.startsWith(".")) {
11941194
kind = MethodKind.INSTANCE;
@@ -1227,7 +1227,7 @@ public void emit(C context, ObjExpr objx, GeneratorAdapter gen) {
12271227
buildThunk(context, this).emit(context, objx, gen);
12281228
}
12291229

1230-
// Expr impl - method value, always an AFn
1230+
// Expr impl - method value is an AFn, field overload has field type
12311231

12321232
@Override
12331233
public boolean hasJavaClass() {
@@ -1236,7 +1236,12 @@ public boolean hasJavaClass() {
12361236

12371237
@Override
12381238
public Class getJavaClass() {
1239-
return tagClass;
1239+
if (tagClass != null)
1240+
return tagClass;
1241+
else if (preferOverloadedField())
1242+
return fieldOverload.getJavaClass();
1243+
else
1244+
return AFn.class;
12401245
}
12411246

12421247
// TBD: caching/reuse of thunks

‎test/clojure/test_clojure/param_tags.clj‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@
194194
(is (= "int-int" (clojure.test.SwissArmy/.doppelganger (clojure.test.SwissArmy/new) (int 1) (int 2))))
195195
(is (= "int-int" (apply clojure.test.SwissArmy/.doppelganger (clojure.test.SwissArmy/new) (int 1) (int 2) [])))))
196196

197+
(deftest field-overload-propagates-type
198+
(testing "field overload without param-tags propagates field type"
199+
(should-not-reflect
200+
(let [a clojure.test.SwissArmy/doppelganger] (.substring a 0)))))
201+
197202
(defmacro arg-tags-called-in-macro
198203
[a-type b-type a b]
199204
`(^[~a-type ~b-type] SwissArmy/staticArityOverloadMethod ~a ~b))

0 commit comments

Comments
 (0)