Aladdin - Scala Bugtracking
[#1288] project: compiler priority: medium category: bug
submitter assigned to status date submitted
Stephane Burak moved to trac 2007-08-23 13:13:04.0
subject [contrib #756] Exception catching code
code
The new exception matching code works great (thank you!) but I recently
found another case that fails.  This is with 2.6.0-RC1.

The following code shows that all exceptions match the first catch
clause.  This ticket may be considered a follow up to

http://scala-webapps.epfl.ch/bugtracking/contribs/display.do?id=649
http://scala-webapps.epfl.ch/bugtracking/bugs/displayItem.do?id=1168

Regards,
Blair

class MyException1 extends Exception

// Commenting out the following line and uncommenting the second line
// will cause the test to succeed.
trait SpecialException extends MyException1
// trait SpecialException

class MyException2 extends MyException1 with SpecialException

object Test extends Application
{
  Array[Throwable](new Exception("abc"),
                   new MyException1,
                   new MyException2).foreach { e =>
    try {
      throw e
    }
    catch {
      case e : SpecialException => {
        assume(e.isInstanceOf[SpecialException])
      }
      case e => {
        assume(e.isInstanceOf[Throwable])
      }
    }
  }
}
what happened
java.lang.Error: assumption failed
        at scala.Predef$.assume(Predef.scala:101)
        at Test$$anonfun$0.apply(t2.scala:21)
        at Test$$anonfun$0.apply(t2.scala:15)
        at scala.Iterator$class.foreach(Iterator.scala:375)
        at scala.runtime.BoxedArray$$anon$0.foreach(BoxedArray.scala:46)
        at scala.Iterable$class.foreach(Iterable.scala:241)
        at scala.runtime.BoxedArray.foreach(BoxedArray.scala:25)
        at Test$.(t2.scala:15)
        at Test$.(t2.scala)
        at Test.main(t2.scala)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at scala.tools.nsc.ObjectRunner$$anonfun$0.apply(ObjectRunner.scala:75)
        at scala.tools.nsc.ObjectRunner$.withContextClassLoader(ObjectRunner.scala:49)
        at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:74)
        at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:154)
        at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
what expected No assertions
[back to overview]
Changes of this bug report
Stephane  edited on  2007-08-23 13:13:37.0
Gilles  edited on  2007-08-29 09:54:44.0