Aladdin - Scala Bugtracking
[#788] project: compiler priority: low category: bug
submitter assigned to status date submitted
Sean Martin fixed 2006-10-23 23:57:44.0
subject match casts combined with original type broken
code
package test;

trait Test {
  type Node <: NodeImpl;
  trait NodeImpl;
  type Expression <: Node with ExpressionImpl;
  trait ExpressionImpl extends NodeImpl { 
    def self : Expression;
  }
  type Named <: Node with NamedImpl;
  trait NamedImpl extends NodeImpl {
    def self : Named;
  }
  def asExpression(e : ExpressionImpl) : Named = {
    e match {
    case f : NamedImpl => f.self;
    case _ => null;
    }
  }
}
what happened
ype mismatch;
found   : Test.this.Expression
required: Test.this.Named	test24/src/test	Test.scala	line 16	1161637333617	184924
what expected f.self should resolve to self call in NamedImpl, not ExpressionImpl. The work around here is to upcast e to any (using (e:Any) match...) to throw off any type combinations by the matcher. To avoid upcasting, the type of the match should occur after types derived from the value being matched. In this example, the type of f is NamedImpl with ExpressionImpl, but should be ExpressionImpl with NamedImpl (I guess....), or better yet: Expression with NamedImpl (why does matching throw off the type parameter?).
[back to overview]
Changes of this bug report
Martin  edited on  2006-10-26 12:18:12.0
The type of `f' is now ExpressionImpl with NamedImpl.