Why do these type arguments not conform to a type refinement?

≡放荡痞女 提交于 2019-12-05 21:34:44

This seems to be the answer:

S specializes type A?

The question about specialize comes from here: T { type A = A0 }. This is the type T with type A specialized -- meaning, it is more restricted than the original T.

The answer to that question is no -- there's no constrains on S that it be specialized.

In order to conform to the type constraints, S would have to be a subtype of T { type A = A0 }, but it is only a subtype of T.

I'm not an expert on this topic, I just played around with your code and found out that the problem is not the S#A part, but the S part.

If you write the code like this:

trait T { type A }
trait GenFoo[A0, S <: T] // the { type A = A0 } part is not there anymore
trait Foo[S <: T] extends GenFoo[S#A, S]

then it compiles, because S in Foo[S <: T] conforms to the S in GenFoo[A0, S <: T].

In your example the compiler knows that S is a subtype of T and therefore has the type A defined, but it does not come to the point, where it can verify that the A in S is the S#A.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!