Aladdin - Scala Bugtracking
[#1119] project: compiler priority: low category: missing feature
submitter assigned to status date submitted
Nikolay Martin fixed 2007-05-20 15:40:16.0
subject [contrib #478] equivalent to requires for virtual types
code
This request is for an alternative to

  trait B[T <: B[T]] requires T {}

that uses virtual types instead of generics.



I've raised the issue on the mailing list and haven't heard that there is an alternative.
http://article.gmane.org/gmane.comp.lang.scala.user/202
http://article.gmane.org/gmane.comp.lang.scala.user/211




Here is one possible syntax, with the error it currently generates

trait B
{
     type T >: this.type <: B


     // compile-time check: have we achieved our objective?
     def test: T = this
}


error: type mismatch;
 found   : B
 required: B.this.T
     def test: T = this
                   ^
what happened
compilation error
what expected I have refined the condition when to use the singleton type, so that the example now compiles.
[back to overview]
Changes of this bug report
Nikolay  edited on  2007-05-20 15:40:33.0
Martin  edited on  2007-05-30 12:12:46.0