Aladdin - Scala Bugtracking
[#694] project: compiler priority: low category: missing feature
submitter assigned to status date submitted
Sean Martin fixed 2006-08-07 14:52:23.0
subject case objects as patterns broken
code
object test3 {
  trait Type[T];
  case object IntType extends Type[Int];
  case object StringType extends Type[String];

  def f[T](t : Type[T]) : T = t match {
  case IntType => 10;
  case StringType => "hello";
  }
}
what happened
doesn't compile.
what expected
[back to overview]
Changes of this bug report
Martin  edited on  2006-08-20 13:20:58.0
We can change this, but only if the pattern matcher treats case objects specially. Right now, I believe it it would translate this into an equality test
 if (t == IntType)
The problem is that equality does not imply that the operands have the same type. I.e. we could write an IntType object as:
object IntType {
  def equals(other: Any) = true
}
If the pattern matcher translates this into an `eq' test instead, we can assume that the types of the operands are the same, and subsequently can strengthen the type checker. So I reassigned to Burak for the moment. He should reassign to me once he is done. Also, we should discuss at a Scala meeting.
Burak  edited on  2006-10-11 14:47:55.0
Pattern matcher uses eq for objects for some time now, so I reassign to Martin.
Martin  edited on  2006-10-31 11:14:24.0
case object now have GADT effects