Skip to content

Commit ff90e42

Browse files
committedJun 11, 2018
Always cast return value to return type. Fixes #5204.
This issue was discovered by implementing an interface that returns a JRuby type, like RubyArray. Because the JRuby types implement IRubyObject, the logic for casting was not used, when at least the cast should be present in all cases.
1 parent 3950c09 commit ff90e42

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed
 

‎core/src/main/java/org/jruby/java/codegen/RealClassGenerator.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -822,12 +822,13 @@ public static void coerceResultAndReturn(SkinnyMethodAdapter mv, Class returnTyp
822822
}
823823
}
824824
} else {
825+
// if the return type is not an IRubyObject implementer, coerce to that type before casting
825826
if (!IRubyObject.class.isAssignableFrom(returnType)) {
826827
mv.ldc(Type.getType(returnType));
827828
mv.invokeinterface(
828829
p(IRubyObject.class), "toJava", sig(Object.class, Class.class));
829-
mv.checkcast(p(returnType));
830830
}
831+
mv.checkcast(p(returnType));
831832
mv.areturn();
832833
}
833834
} else {

0 commit comments

Comments
 (0)
Please sign in to comment.