comparison 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
comparison
equal deleted inserted replaced
18769:144fba40c979 18770:2c669386b5d0
332 return a; 332 return a;
333 } 333 }
334 334
335 } 335 }
336 336
337 @NodeChildren({@NodeChild("a")}) 337 /* Throwing RuntimeExceptions without rewriteOn is allowed. */
338 static class FallthroughTest6 extends ValueNode { 338 @NodeChildren({@NodeChild("a")})
339 339 static class FallthroughExceptionType0 extends ValueNode {
340 static int fallthrough1; 340
341 static int fallthrough2; 341 @Specialization
342 static int fallthrough3; 342 int do4(int a) throws RuntimeException {
343 static int fallthrough4; 343 return a;
344 344 }
345 @Specialization(order = 1, rewriteOn = ArithmeticException.class) 345
346 int do4(int a) throws ArithmeticException { 346 }
347 return a; 347
348 } 348 /* Non runtime exceptions must be verified. */
349 349 @NodeChildren({@NodeChild("a")})
350 @Specialization(order = 2, rewriteOn = ArithmeticException.class) 350 static class FallthroughExceptionType1 extends ValueNode {
351 int do2(int a) throws ArithmeticException { 351
352 return a; 352 @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'.")
353 } 353 @Specialization(rewriteOn = Throwable.class)
354 354 int do4(int a) {
355 @Specialization(order = 3, rewriteOn = ArithmeticException.class) 355 return a;
356 int do3(int a) throws ArithmeticException { 356 }
357 return a; 357
358 } 358 }
359 359
360 @Specialization(order = 4, rewriteOn = ArithmeticException.class) 360 /* Checked exception must be verified. */
361 int do1(int a) throws ArithmeticException { 361 @NodeChildren({@NodeChild("a")})
362 return a; 362 static class FallthroughExceptionType2 extends ValueNode {
363 } 363
364 364 @ExpectError("A checked exception 'java.lang.Throwable' is thrown but is not specified using the rewriteOn property. "
365 @Specialization 365 + "Checked exceptions that are not used for rewriting are not handled by the DSL. Use RuntimeExceptions for this purpose instead.")
366 double do5(double a) { 366 @Specialization
367 int do4(int a) throws Throwable {
367 return a; 368 return a;
368 } 369 }
369 370
370 } 371 }
371 372