Well the cause is that it is in infinite recursion, thanks to implicit conversion. Remove implicit
keyword from xToNextPage
and it shows an error:
<console>:29: error: type mismatch;
found : X with NextPage[X,Bar]
required: NextPage[X,Y]
new X(x.year) with NextPage[X, Bar] {
Obviously your function declaration says that you are returning NextPage[X, Y]
but you actually return NextPage[X,Any]
.
It goes in recursion because when marked as implicit
because your function return type is of [X, Y]
. But because you are returning [X,Any]
, it again calls the implicit function xToNextPage
to try converting it.
Solution: Change declaration to:
trait NextPage[Curr, +Next] {
def next : Next
}
implicit def xToNextPage[Y](x : X) : NextPage[X, Any]