No type parameters for method flatMap in for comprehension


#1

Hi,

I am getting the following error in a for comprehension:

no type parameters for method flatMap

— because —
[error] argument expression’s type is not compatible with formal parameter type;

It appears the have something to do with creating a new instance inside the for comprehension.
In one case the error can be worked around by making the return type of the for explicit. For the second case that also does not work.

I’ve made a reproducer here:

The errors only occur on 2.12.[>=4] and 2.12-0-M3. Not on dotty (0.8.0rc1)

I checked the bug database i found some bugs which look somewhat related but i am really not sure.

Thanks,
Jeroen

Full error:

Reproducer.scala:36:7: no type parameters for method flatMap: (f: ((Main.wrappedRequest.Response, WrappedRequest[APIRequest])) => scala.concurrent.Future[S])(implicit executor: scala.concurrent.ExecutionContext)scala.concurrent.Future[S] exist so that it can be applied to arguments (((Main.wrappedRequest.Response, WrappedRequest[APIRequest])) => scala.concurrent.Future[WrappedResponse[newWrappedRequest.wrapped.Response]] forSome { val newWrappedRequest: WrappedRequest[APIRequest] })
[error]  --- because ---
[error] argument expression's type is not compatible with formal parameter type;
[error]  found   : ((Main.wrappedRequest.Response, WrappedRequest[APIRequest])) => scala.concurrent.Future[WrappedResponse[newWrappedRequest.wrapped.Response]] forSome { val newWrappedRequest: WrappedRequest[APIRequest] }
[error]     (which expands to)  ((WrappedResponse[Main.wrappedRequest.wrapped.Response], WrappedRequest[APIRequest])) => scala.concurrent.Future[WrappedResponse[newWrappedRequest.wrapped.Response]] forSome { val newWrappedRequest: WrappedRequest[APIRequest] }
[error]  required: ((Main.wrappedRequest.Response, WrappedRequest[APIRequest])) => scala.concurrent.Future[?S]
[error]     (which expands to)  ((WrappedResponse[Main.wrappedRequest.wrapped.Response], WrappedRequest[APIRequest])) => scala.concurrent.Future[?S]
[error]     _ <- wrappedApiClient.request(wrappedRequest)
[error]       ^

#2

Hello @jeroentv, it looks like the best place to report this misbehaviour is https://github.com/scala/bug/.


#3

Hi,

I wasn’t sure this was actually a bug or a known limitation of scalac. I will report it as a bug then.

Thanks!