You should just remove type parameter from loop
method. Replace loop[T]
with loop
.
With loop[T]
you are creating new type parameter with name T
, so T
outside loop
method and T
in loop
method are different type aliases with the same name.
It's called shadowing.
See these answers for similar problems: