Aladdin - Scala Bugtracking
[#695] project: specification priority: low category: missing feature
submitter assigned to status date submitted
Sean Martin fixed 2006-08-08 14:19:33.0
subject inner type tests not safe
code
object test extends Application {
  class MyOuter[T](t : T) {
    class MyInner { val s = t; }
  }
  val withString = new MyOuter("hello");
  val withInt    = new MyOuter(10);
  val innerWithInt = new withInt.MyInner;
  def f(a : Any) = a match {
  case a : withString.MyInner => Console.println("size: " + a.s.length);
  case _ =>
  }
  f(innerWithInt);
}
what happened
Exception in thread "main" java.lang.ExceptionInInitializerError
	at test.test.main(test.scala)
Caused by: java.lang.ClassCastException: scala.runtime.BoxedInt
	at test.test$.f(test.scala:12)
	at test.test$.(test.scala:15)
	at test.test$.(test.scala)
	... 1 more
what expected Ideally, isInstanceOf should test the outer instance when testing an object against a qualified type (this is doable, the outer value is available or the type couldn't be expressed). If that isn't desirable, the compiler should emit an error or warning when testing an object against a qualified type (as Java does with type variable tests).
[back to overview]
Changes of this bug report
Martin  edited on  2006-08-20 13:14:49.0
I changed to a spec missing feature, because the spec right now says that type tests apply to the erasure of a type. To discuss in a scala meeting, I guess...
Martin  edited on  2006-09-05 13:16:19.0
Burak  edited on  2006-09-19 19:59:07.0
Just to say, the code passes now, after all that explicitouter and transmatch rewriting. I leave it open as a specification issue, though I don't really feel inspired to produce a spec for this... but I volunteer for "remembering it", for now.
Burak  edited on  2006-10-23 14:37:55.0
I reassign this to Martin now -- the given example now works but the story of outer tests in patterns is untold in the spec and I think it had some parts that needed elaboration.
Martin  edited on  2006-12-06 15:43:51.0
Spec is fixed now, so the bug can be closed.