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
In the following example, call sites using p1 (which uses the match type as a bound) diverge, whereas call sites using p2 (which uses the match type as a constraint) compile successfully.
objectTest {
// The identity on types of the form N | P[a, P[b, ... P[z, N]]]typeNested[X, P[_, _], N] =Xmatch {
caseN=>NcaseP[a, b] =>P[a, Nested[b, P, N]]
}
// Type bound:// Recursion limit exceeded.// Maybe there is an illegal cyclic reference?defp1[T<:Nested[T, Tuple2, Unit]](t: T):T= t
p1(())
p1((23, ()))
p1(("foo", (23, ())))
// Type constraint: OKdefp2[T](t: T)(erased implicitev: T<:<Nested[T, Tuple2, Unit]):T= t
p2(())
p2((23, ()))
p2(("foo", (23, ())))
}
It's not immediately obvious to me why the two cases should differ.
The text was updated successfully, but these errors were encountered:
I suspected that #5657 might improve things on this issue, but sadly not.
Reduced the example more to,
objectTest {
// The identity on UnittypeIdUnit[X] =Xmatch {
caseUnit=>Unit
}
// Type bound:// Recursion limit exceeded.// Maybe there is an illegal cyclic reference?defp1[T<:IdUnit[T]](t: T):T= t
p1(())
// Type constraint: OKdefp2[T](t: T)(erased implicitev: T<:<IdUnit[T]):T= t
p2(())
}
milessabin
added a commit
to milessabin/dotty
that referenced
this issue
Jan 6, 2019
The issue described in #5682 is that F-bounds involving match types are problematic. Here's an idea to possibly explore later: are "indirect" F-bounds problematic? Consider:
defp1[T, Y>:T<:Nested[T, Tuple2, Unit](t: T):T= t
The above enforces that T <: Y <: Nested[T, Tuple2, Unit], which still indirectly enforces that T <: Nested[T, Tuple2, Unit]. It also still causes a cyclic reference error. The following semi-works, but only for equivalent of p1(()):
objectTest {
// The identity on types of the form N | P[a, P[b, ... P[z, N]]]typeNested[X, P[_, _], N] =Xmatch {
caseN=>NcaseP[a, b] =>P[a, Nested[b, P, N]]
}
classFoo[T] { defapply[Y>:T<:Nested[T, Tuple2, Unit]](t: T):T= t }
deffoo[T] =newFoo[T]
foo.apply(())
}
In the following example, call sites using
p1
(which uses the match type as a bound) diverge, whereas call sites usingp2
(which uses the match type as a constraint) compile successfully.It's not immediately obvious to me why the two cases should differ.
The text was updated successfully, but these errors were encountered: