Aladdin - Scala Bugtracking
[#511] project: specification priority: low category: bug
submitter assigned to status date submitted
Philippe Martin open 2006-01-10 17:37:15.0
subject Is it legal to use type members of the self-type in the signature of the class?
code
abstract class C requires D {
  def t: T;
}

abstract class D extends C {
  type T;
}

class E extends D {
  type T = Int;
  def t: T = 0;
}

object Test {
  val c: C = new E;
  val t = c.t;
}
what happened
No error.
what expected Maybe an error. What's the type of Test.t. The analyzer infers Test.c.T but that's not a legal type as T is not a member of C. Maybe it should not be legal to use T in the signature of C members.
[back to overview]
Changes of this bug report
Burak  edited on  2006-05-28 22:21:16.0
Arguably, every instance of C is also an instance of D. So C is a subtype of D, and it's ok to access the members of D not only inside but also outside (the public ones).
This sort of question seems to lead a bit in the direction of C++ inheritance, which is clumsy: one can be inherit privately from a class or publicly.
'requires' resembles C++ private inheritance [C++ FAQ lite] in that one can observe a different type for this. I also think it makes sense for C to access the protected members of D.