Mercurial > hg > graal-compiler
diff graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/SpecializationFallthroughTest.java @ 18770:2c669386b5d0
Truffle-DSL: fix crash if type in rewriteOn is not of type Throwable. Improved error messages for Specialization#rewriteOn.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 02 Jan 2015 14:31:51 +0100 |
parents | c88ab4f1f04a |
children | 08aa0372dad4 |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/SpecializationFallthroughTest.java Wed Dec 31 17:35:10 2014 +0000 +++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/SpecializationFallthroughTest.java Fri Jan 02 14:31:51 2015 +0100 @@ -334,36 +334,37 @@ } + /* Throwing RuntimeExceptions without rewriteOn is allowed. */ @NodeChildren({@NodeChild("a")}) - static class FallthroughTest6 extends ValueNode { + static class FallthroughExceptionType0 extends ValueNode { - static int fallthrough1; - static int fallthrough2; - static int fallthrough3; - static int fallthrough4; - - @Specialization(order = 1, rewriteOn = ArithmeticException.class) - int do4(int a) throws ArithmeticException { + @Specialization + int do4(int a) throws RuntimeException { return a; } - @Specialization(order = 2, rewriteOn = ArithmeticException.class) - int do2(int a) throws ArithmeticException { + } + + /* Non runtime exceptions must be verified. */ + @NodeChildren({@NodeChild("a")}) + static class FallthroughExceptionType1 extends ValueNode { + + @ExpectError("A rewriteOn checked exception was specified but not thrown in the method's throws clause. The @Specialization method must specify a throws clause with the exception type 'java.lang.Throwable'.") + @Specialization(rewriteOn = Throwable.class) + int do4(int a) { return a; } - @Specialization(order = 3, rewriteOn = ArithmeticException.class) - int do3(int a) throws ArithmeticException { - return a; - } + } - @Specialization(order = 4, rewriteOn = ArithmeticException.class) - int do1(int a) throws ArithmeticException { - return a; - } + /* Checked exception must be verified. */ + @NodeChildren({@NodeChild("a")}) + static class FallthroughExceptionType2 extends ValueNode { + @ExpectError("A checked exception 'java.lang.Throwable' is thrown but is not specified using the rewriteOn property. " + + "Checked exceptions that are not used for rewriting are not handled by the DSL. Use RuntimeExceptions for this purpose instead.") @Specialization - double do5(double a) { + int do4(int a) throws Throwable { return a; }