@@ -1101,9 +1101,14 @@ public InstanceMethodExpr(String source, int line, Expr target, String methodNam
1101
1101
if (methods .size () > 1 )
1102
1102
{
1103
1103
ArrayList <Class []> params = new ArrayList ();
1104
+ ArrayList <Class > rets = new ArrayList ();
1104
1105
for (int i = 0 ; i < methods .size (); i ++)
1105
- params .add (((java .lang .reflect .Method ) methods .get (i )).getParameterTypes ());
1106
- methodidx = getMatchingParams (methodName , params , args );
1106
+ {
1107
+ java .lang .reflect .Method m = (java .lang .reflect .Method )methods .get (i );
1108
+ params .add (m .getParameterTypes ());
1109
+ rets .add (m .getReturnType ());
1110
+ }
1111
+ methodidx = getMatchingParams (methodName , params , args ,rets );
1107
1112
}
1108
1113
java .lang .reflect .Method m =
1109
1114
(java .lang .reflect .Method ) (methodidx >= 0 ? methods .get (methodidx ) : null );
@@ -1249,9 +1254,14 @@ public StaticMethodExpr(String source, int line, Class c, String methodName, IPe
1249
1254
if (methods .size () > 1 )
1250
1255
{
1251
1256
ArrayList <Class []> params = new ArrayList ();
1257
+ ArrayList <Class > rets = new ArrayList ();
1252
1258
for (int i = 0 ; i < methods .size (); i ++)
1253
- params .add (((java .lang .reflect .Method ) methods .get (i )).getParameterTypes ());
1254
- methodidx = getMatchingParams (methodName , params , args );
1259
+ {
1260
+ java .lang .reflect .Method m = (java .lang .reflect .Method ) methods .get (i );
1261
+ params .add (m .getParameterTypes ());
1262
+ rets .add (m .getReturnType ());
1263
+ }
1264
+ methodidx = getMatchingParams (methodName , params , args ,rets );
1255
1265
}
1256
1266
method = (java .lang .reflect .Method ) (methodidx >= 0 ? methods .get (methodidx ) : null );
1257
1267
if (method == null && RT .booleanCast (RT .WARN_ON_REFLECTION .get ()))
@@ -2007,7 +2017,7 @@ static boolean subsumes(Class[] c1, Class[] c2){
2007
2017
return better ;
2008
2018
}
2009
2019
2010
- static int getMatchingParams (String methodName , ArrayList <Class []> paramlists , IPersistentVector argexprs )
2020
+ static int getMatchingParams (String methodName , ArrayList <Class []> paramlists , IPersistentVector argexprs , List < Class > rets )
2011
2021
throws Exception {
2012
2022
//presumes matching lengths
2013
2023
int matchIdx = -1 ;
@@ -2033,8 +2043,12 @@ static int getMatchingParams(String methodName, ArrayList<Class[]> paramlists, I
2033
2043
matchIdx = i ;
2034
2044
tied = false ;
2035
2045
}
2036
- else if (!(subsumes (paramlists .get (matchIdx ), paramlists .get (i ))
2037
- || Arrays .equals (paramlists .get (matchIdx ), paramlists .get (i ))))
2046
+ else if (Arrays .equals (paramlists .get (matchIdx ), paramlists .get (i )))
2047
+ {
2048
+ if (rets .get (matchIdx ).isAssignableFrom (rets .get (i )))
2049
+ matchIdx = i ;
2050
+ }
2051
+ else if (!(subsumes (paramlists .get (matchIdx ), paramlists .get (i ))))
2038
2052
tied = true ;
2039
2053
}
2040
2054
}
@@ -2060,13 +2074,15 @@ public NewExpr(Class c, IPersistentVector args, int line) throws Exception{
2060
2074
Constructor [] allctors = c .getConstructors ();
2061
2075
ArrayList ctors = new ArrayList ();
2062
2076
ArrayList <Class []> params = new ArrayList ();
2077
+ ArrayList <Class > rets = new ArrayList ();
2063
2078
for (int i = 0 ; i < allctors .length ; i ++)
2064
2079
{
2065
2080
Constructor ctor = allctors [i ];
2066
2081
if (ctor .getParameterTypes ().length == args .count ())
2067
2082
{
2068
2083
ctors .add (ctor );
2069
2084
params .add (ctor .getParameterTypes ());
2085
+ rets .add (c );
2070
2086
}
2071
2087
}
2072
2088
if (ctors .isEmpty ())
@@ -2075,7 +2091,7 @@ public NewExpr(Class c, IPersistentVector args, int line) throws Exception{
2075
2091
int ctoridx = 0 ;
2076
2092
if (ctors .size () > 1 )
2077
2093
{
2078
- ctoridx = getMatchingParams (c .getName (), params , args );
2094
+ ctoridx = getMatchingParams (c .getName (), params , args , rets );
2079
2095
}
2080
2096
2081
2097
this .ctor = ctoridx >= 0 ? (Constructor ) ctors .get (ctoridx ) : null ;
0 commit comments