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
scala>defunbox[A](s: Stream[A]) = s match {caseUnfold(s, f) => (s, f)}
--Warning: <console> ----------------------------------------------------------7|defunbox[A](s: Stream[A]) = s match {caseUnfold(s, f) => (s, f)}
|^^^^^^^^^^^^|There is no best instantiation of pattern typeUnfold[Any^, A^]
| that makes it a subtype of selector typeStream[A].
|Non-variant typevariableS cannot be uniquely instantiated.
| (This would be an error under strict mode)
defunbox[A](s: Stream[A]): [A] => (s: Stream[A])(Any, Any=>Option[(A, Any)])
But there is a ‘best’ choice, which is moreover sound, which is to introduce a fresh type variable, as you can write explicitly with type pattern variables.
scala>defunbox[A](s: Stream[A]) = s match {
caseu: Unfold[ts, A] =>
u.s: ts // the name chosen in this block
(u.s, u.f)
}
defunbox[A](s: Stream[A]): [A] => (s: Stream[A])(Any, _ =>Option[(A, Any)])
Given
You get this warning, and an associated unsound inferred type, as in SI-6680 “Unsoundness bug in pattern matcher when pattern reveals existentials”:
But there is a ‘best’ choice, which is moreover sound, which is to introduce a fresh type variable, as you can write explicitly with type pattern variables.
This is based on 39c27b6.
/cc @pchiusano
The text was updated successfully, but these errors were encountered: