KT-2823 TypeCastException has no message
#KT-2823 Fixed
This commit is contained in:
@@ -57,6 +57,7 @@ import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -3156,7 +3157,9 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
v.dup();
|
||||
Label nonnull = new Label();
|
||||
v.ifnonnull(nonnull);
|
||||
throwNewException(CLASS_TYPE_CAST_EXCEPTION);
|
||||
throwNewException(CLASS_TYPE_CAST_EXCEPTION, DescriptorRenderer.TEXT.renderType(leftType) +
|
||||
" cannot be cast to " +
|
||||
DescriptorRenderer.TEXT.renderType(rightType));
|
||||
v.mark(nonnull);
|
||||
}
|
||||
}
|
||||
@@ -3376,10 +3379,20 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
return false;
|
||||
}
|
||||
|
||||
private void throwNewException(final String className) {
|
||||
private void throwNewException(@NotNull final String className) {
|
||||
throwNewException(className, null);
|
||||
}
|
||||
|
||||
private void throwNewException(@NotNull final String className, @Nullable final String message) {
|
||||
v.anew(Type.getObjectType(className));
|
||||
v.dup();
|
||||
v.invokespecial(className, "<init>", "()V");
|
||||
if (message != null) {
|
||||
v.visitLdcInsn(message);
|
||||
v.invokespecial(className, "<init>", "(Ljava/lang/String;)V");
|
||||
}
|
||||
else {
|
||||
v.invokespecial(className, "<init>", "()V");
|
||||
}
|
||||
v.athrow();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// KT-2823 TypeCastException has no message
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
val a: Any? = null
|
||||
a as Array<String>
|
||||
}
|
||||
catch(e: TypeCastException) {
|
||||
if (e.getMessage() == "jet.Any? cannot be cast to jet.Array<jet.String>") {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
return "fail"
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public class NamespaceGenTest extends CodegenTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations();
|
||||
}
|
||||
|
||||
public void testPSVM() throws Exception {
|
||||
@@ -477,6 +477,10 @@ public class NamespaceGenTest extends CodegenTestCase {
|
||||
blackBoxFile("checkCast.jet");
|
||||
}
|
||||
|
||||
public void testTypeCastException() throws Exception {
|
||||
blackBoxFile("typeCastException.jet");
|
||||
}
|
||||
|
||||
public void testPutBooleanAsVoid() throws Exception {
|
||||
loadText("class C(val x: Int) { { x > 0 } } fun box() { val c = C(0) } ");
|
||||
final Method main = generateFunction();
|
||||
|
||||
@@ -20,4 +20,8 @@ package jet;
|
||||
* @author yole
|
||||
*/
|
||||
public class TypeCastException extends ClassCastException {
|
||||
|
||||
public TypeCastException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user