@@ -1424,7 +1424,7 @@ else if(primc == double.class && parameterTypes[i] == float.class)
1424
1424
}
1425
1425
catch (Exception e1 )
1426
1426
{
1427
- e1 . printStackTrace ( RT . errPrintWriter () );
1427
+ throw Util . sneakyThrow ( e1 );
1428
1428
}
1429
1429
1430
1430
}
@@ -1606,7 +1606,7 @@ public boolean hasJavaClass(){
1606
1606
}
1607
1607
1608
1608
public Class getJavaClass () {
1609
- return tag != null ? HostExpr .tagToClass (tag ) : method .getReturnType ();
1609
+ return retType (( tag != null )? HostExpr .tagToClass (tag ): null , ( method != null )? method .getReturnType (): null );
1610
1610
}
1611
1611
}
1612
1612
@@ -1819,7 +1819,7 @@ public boolean hasJavaClass(){
1819
1819
}
1820
1820
1821
1821
public Class getJavaClass () {
1822
- return tag != null ? HostExpr .tagToClass (tag ) : method .getReturnType ();
1822
+ return retType (( tag != null )? HostExpr .tagToClass (tag ): null , ( method != null )? method .getReturnType (): null );
1823
1823
}
1824
1824
}
1825
1825
@@ -3465,7 +3465,7 @@ public boolean hasJavaClass() {
3465
3465
}
3466
3466
3467
3467
public Class getJavaClass () {
3468
- return tag != null ? HostExpr .tagToClass (tag ) : retClass ;
3468
+ return retType (( tag != null )? HostExpr .tagToClass (tag ): null , retClass ) ;
3469
3469
}
3470
3470
3471
3471
public boolean canEmitPrimitive (){
@@ -8319,6 +8319,27 @@ public void emit(ObjExpr obj, ClassVisitor cv){
8319
8319
}
8320
8320
}
8321
8321
8322
+ static boolean inty (Class c ){
8323
+ return c == int .class
8324
+ || c == short .class
8325
+ || c == byte .class
8326
+ || c == char .class ;
8327
+ }
8328
+
8329
+ static Class retType (Class tc , Class ret ){
8330
+ if (tc == null )
8331
+ return ret ;
8332
+ if (ret == null )
8333
+ return tc ;
8334
+ if (ret .isPrimitive () && tc .isPrimitive ()){
8335
+ if ((inty (ret ) && inty (tc )) || (ret == tc ))
8336
+ return tc ;
8337
+ throw new UnsupportedOperationException ("Cannot coerce " + ret +
8338
+ " to " + tc + ", use a cast instead" );
8339
+ }
8340
+ return tc ;
8341
+ }
8342
+
8322
8343
static Class primClass (Symbol sym ){
8323
8344
if (sym == null )
8324
8345
return null ;
0 commit comments