-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow recursive type projections #1291
Comments
Imported From: https://issues.scala-lang.org/browse/SI-1291?orig=1 |
Geoffrey Alan Washburn (washburn) said: |
@odersky said: |
Geoffrey Alan Washburn (washburn) said: |
@jesnor said: object ProjTest {
trait MInt { type Type }
trait _0 extends MInt { type Type = Boolean }
trait Succ[Pre <: MInt] extends MInt { type Type = Pre#Type }
type _1 = Succ[_0]
type _2 = Succ[_1]
type X1 = _0#Type // Ok
type X2 = _1#Type // Ok
type X3 = _2#Type // Compiler error, illegal cyclic reference involving type Type
} Which doesn't contain a loop and should be expanded to: _2#Type = Succ[_1]#Type = _1#Type = Succ[_0]#Type = _0#Type = Boolean Can you verify if this works with your experimental branch? If it does, it could be hopefully be used to implement more advanced things like HList (see http://jnordenberg.blogspot.com). |
@odersky said: |
@paulp said: |
Currently the Scala compiler outputs an "illegal cyclic reference" error when a type projection references itself, even though the containing type is instantiated with different type parameters, see the code example below. This severely limits the possibilities for meta programming (as done in C++) in Scala, which is a shame because the language has the expressive power to make it work.
I see two solutions to this limitation:
Remove the cyclic reference check and add a maximum type alias/projection depth similar to the template instantiation depth limit found in many C++ compilers (including GCC, -ftemplate-depth-n).
Enhance the cyclic reference checker, for example if the path contains A[Int]#Type and A[Float]#Type it shouldn't be considered a cyclic reference.
The text was updated successfully, but these errors were encountered: