Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2af7d08

Browse filesBrowse files
committed
Modified to check field/method overloads in analyzeSymbol. QME.emit/eval checks for overloads and emits field or thunk.
1 parent 9699878 commit 2af7d08
Copy full SHA for 2af7d08

File tree

Expand file treeCollapse file tree

1 file changed

+49
-32
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+49
-32
lines changed

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

Copy file name to clipboardExpand all lines: src/jvm/clojure/lang/Compiler.java
+49-32Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,12 +1165,17 @@ static class QualifiedMethodExpr implements Expr {
11651165
private final String methodName;
11661166
private final MethodKind kind;
11671167
private final Class tagClass;
1168+
private final StaticFieldExpr fieldOverload;
11681169

11691170
private enum MethodKind {
11701171
CTOR, INSTANCE, STATIC
11711172
}
11721173

1173-
public QualifiedMethodExpr(Class methodClass, Symbol sym){
1174+
public QualifiedMethodExpr(Class methodClass, Symbol sym) {
1175+
this(methodClass, sym, null);
1176+
}
1177+
1178+
public QualifiedMethodExpr(Class methodClass, Symbol sym, StaticFieldExpr fieldOL) {
11741179
c = methodClass;
11751180
methodSymbol = sym;
11761181
tagClass = tagOf(sym) != null ? HostExpr.tagToClass(tagOf(sym)) : AFn.class;
@@ -1187,18 +1192,28 @@ else if(sym.name.equals("new")) {
11871192
kind = MethodKind.STATIC;
11881193
methodName = sym.name;
11891194
}
1195+
fieldOverload = fieldOL;
11901196
}
11911197

11921198
// Expr impl - invocation, convert to fn expr
1199+
private boolean overloadsField() {
1200+
return fieldOverload != null && paramTagsOf(methodSymbol) == null;
1201+
}
11931202

11941203
@Override
11951204
public Object eval() {
1196-
return buildThunk(C.EVAL, this).eval();
1205+
if(overloadsField())
1206+
return fieldOverload.eval();
1207+
else
1208+
return buildThunk(C.EVAL, this).eval();
11971209
}
11981210

11991211
@Override
12001212
public void emit(C context, ObjExpr objx, GeneratorAdapter gen) {
1201-
buildThunk(context, this).emit(context, objx, gen);
1213+
if(overloadsField())
1214+
fieldOverload.emit(context, objx, gen);
1215+
else
1216+
buildThunk(context, this).emit(context, objx, gen);
12021217
}
12031218

12041219
// Expr impl - method value, always an AFn
@@ -1258,18 +1273,9 @@ private static Set aritySet(Class c, String methodName, MethodKind kind) {
12581273
return res;
12591274
}
12601275

1261-
// Returns a list of methods or ctors matching the name and kind given.
1262-
// Otherwise, will throw if the information provided results in no matches
1263-
public static List<Executable> methodsWithName(Class c, String methodName, MethodKind kind) {
1264-
if (kind == MethodKind.CTOR) {
1265-
List<Executable> ctors = Arrays.asList(c.getConstructors());
1266-
if(ctors.isEmpty())
1267-
throw noMethodWithNameException(c, methodName, kind);
1268-
return ctors;
1269-
}
1270-
1276+
public static List<Executable> methodOverloads(Class c, String methodName, MethodKind kind) {
12711277
final Executable[] methods = c.getMethods();
1272-
List<Executable> res = Arrays.stream(methods)
1278+
return Arrays.stream(methods)
12731279
.filter(m -> m.getName().equals(methodName))
12741280
.filter(m -> {
12751281
switch(kind) {
@@ -1279,6 +1285,19 @@ public static List<Executable> methodsWithName(Class c, String methodName, Metho
12791285
}
12801286
})
12811287
.collect(Collectors.toList());
1288+
}
1289+
1290+
// Returns a list of methods or ctors matching the name and kind given.
1291+
// Otherwise, will throw if the information provided results in no matches
1292+
private static List<Executable> methodsWithName(Class c, String methodName, MethodKind kind) {
1293+
if (kind == MethodKind.CTOR) {
1294+
List<Executable> ctors = Arrays.asList(c.getConstructors());
1295+
if(ctors.isEmpty())
1296+
throw noMethodWithNameException(c, methodName, kind);
1297+
return ctors;
1298+
}
1299+
1300+
List<Executable> res = methodOverloads(c, methodName, kind);
12821301

12831302
if(res.isEmpty())
12841303
throw noMethodWithNameException(c, methodName, kind);
@@ -4115,7 +4134,7 @@ static Object sigTag(int argcount, Var v){
41154134
return tagOf(sig);
41164135
}
41174136
return null;
4118-
}
4137+
}
41194138

41204139
public InvokeExpr(String source, int line, int column, Symbol tag, Expr fexpr, IPersistentVector args, boolean tailPosition) {
41214140
this.source = source;
@@ -4359,27 +4378,18 @@ static public Expr parse(C context, ISeq form) {
43594378
(KeywordExpr) fexpr, target);
43604379
}
43614380

4381+
// Preserving the existing static field bug that replaces a reference in parens with
4382+
// the field itself rather than trying to invoke the value in the field. This is
4383+
// an exception to the uniform Class/member qualification per CLJ-2806 ticket.
4384+
if(fexpr instanceof StaticFieldExpr)
4385+
return fexpr;
4386+
43624387
PersistentVector args = PersistentVector.EMPTY;
43634388
for(ISeq s = RT.seq(form.next()); s != null; s = s.next())
43644389
{
43654390
args = args.cons(analyze(context, s.first()));
43664391
}
43674392

4368-
if(fexpr instanceof StaticFieldExpr) {
4369-
Class c = ((StaticFieldExpr) fexpr).c;
4370-
String name = ((StaticFieldExpr) fexpr).fieldName;
4371-
4372-
// Preserving the existing static field bug that replaces a reference in parens with
4373-
// the field itself rather than trying to invoke the value in the field. This is
4374-
// an exception to the uniform Class/member qualification per CLJ-2806 ticket.
4375-
if (RT.count(args) == 0 && QualifiedMethodExpr.methodsWithName(c, name, QualifiedMethodExpr.MethodKind.STATIC).isEmpty())
4376-
return fexpr;
4377-
else {
4378-
Symbol sym = Symbol.intern(c.getName(), name);
4379-
return toHostExpr(new QualifiedMethodExpr(c, sym), (String) SOURCE.deref(), lineDeref(), columnDeref(), tagOf(form), tailPosition, args);
4380-
}
4381-
}
4382-
43834393
if(fexpr instanceof QualifiedMethodExpr)
43844394
return toHostExpr((QualifiedMethodExpr)fexpr, (String) SOURCE.deref(), lineDeref(), columnDeref(), tagOf(form), tailPosition, args);
43854395

@@ -7838,8 +7848,15 @@ private static Expr analyzeSymbol(Symbol sym) {
78387848
Class c = HostExpr.maybeClass(nsSym, false);
78397849
if(c != null)
78407850
{
7841-
if((paramTagsOf(sym) == null) && (Reflector.getField(c, sym.name, true) != null))
7842-
return new StaticFieldExpr(lineDeref(), columnDeref(), c, sym.name, tag);
7851+
if(Reflector.getField(c, sym.name, true) != null)
7852+
{
7853+
List<Executable> maybeOverloads = QualifiedMethodExpr.methodOverloads(c, sym.name, QualifiedMethodExpr.MethodKind.STATIC);
7854+
7855+
if(maybeOverloads.isEmpty())
7856+
return new StaticFieldExpr(lineDeref(), columnDeref(), c, sym.name, tag);
7857+
else
7858+
return new QualifiedMethodExpr(c, sym, new StaticFieldExpr(lineDeref(), columnDeref(), c, sym.name, tag));
7859+
}
78437860
else
78447861
return new QualifiedMethodExpr(c, sym);
78457862
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.