You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(if we had directly written def foo[S >: D[T] <: C[T], T >: D[S] <: C[S]] the compiler would have complained via checkNonCyclic:
25|deffoo[S>:D[T] <:C[T], T>:D[S] <:C[S]]:S=???|^|illegal cyclic typereference: lower bound D[T] of typeS refers back to the typeitself
)
It's not clear to me if we can always detect these cycles as we add a bound, so we might have to settle for detecting them at instantiation time and failing then: this is what 74c693c attempts.
This seems to work, but because we don't have a tree position when instantiating a TypeVar, and because type variable instantiation can be delayed, the error ends up being reported at an unrelated point rather than at the actual call-site, I'm not sure how to do better.
EDIT: I don't think detecting these cycles at instantiation time is enough actually, because some operations like avoidance recurse on both the upper and lower bound of a type variable and can get into infinite loops that way: #15393 (comment)
The text was updated successfully, but these errors were encountered:
According to our own comments, cycles are only allowed in the upper-bound of a type variable due to F-bounds which we explicitly handle when instantiating:
https://github.com/lampepfl/dotty/blob/9d687784c30b94d07583885251b2576c3eed1f40/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala#L426-L431
The corresponding logic in addOneBound is https://github.com/lampepfl/dotty/blob/9d687784c30b94d07583885251b2576c3eed1f40/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala#L244-L247
But all of this isn't enough to catch indirect cycles like in
(if we had directly written
def foo[S >: D[T] <: C[T], T >: D[S] <: C[S]]
the compiler would have complained via checkNonCyclic:)
It's not clear to me if we can always detect these cycles as we add a bound, so we might have to settle for detecting them at instantiation time and failing then: this is what 74c693c attempts.
This seems to work, but because we don't have a tree position when instantiating a TypeVar, and because type variable instantiation can be delayed, the error ends up being reported at an unrelated point rather than at the actual call-site, I'm not sure how to do better.
EDIT: I don't think detecting these cycles at instantiation time is enough actually, because some operations like avoidance recurse on both the upper and lower bound of a type variable and can get into infinite loops that way: #15393 (comment)
The text was updated successfully, but these errors were encountered: