scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.73k stars 1.04k forks source link

Tuple#map function interferes with common enriched map operation #10965

Open djspiewak opened 3 years ago

djspiewak commented 3 years ago

Another unminimized one. Sorry… (figured it out: see addendum at the end)

https://github.com/djspiewak/cats-effect/tree/bug/dotty-inference-issue To reproduce, sbt ++3.0.0-M3 kernelJVM/clean kernelJVM/compile. Note that this branch compiles just fine if you do ++2.13.3 or ++2.12.10 instead. One of the offending lines:

https://github.com/djspiewak/cats-effect/blob/bug/dotty-inference-issue/kernel/shared/src/main/scala/cats/effect/kernel/Resource.scala#L871

_(fa.use_ !> fb.allocated).map(_.map(fin => (_: Resource.ExitCase) => fin)))

And the error:

[error] -- [E081] Type Error: /Users/daniel/Development/Scala/cats-effect/series-3.x/kernel/shared/src/main/scala/cats/effect/kernel/Resource.scala:871:43 
[error] 871 |      _(fa.use_ !> fb.allocated).map(_.map(fin => (_: Resource.ExitCase) => fin)))
[error]     |                                           ^^^
[error]     |                      Missing parameter type
[error]     |
[error]     |                      I could not infer the type of the parameter fin.

If I ascribe the correct type for fin, it still doesn't work:

[error] -- [E007] Type Mismatch Error: /Users/daniel/Development/Scala/cats-effect/series-3.x/kernel/shared/src/main/scala/cats/effect/kernel/Resource.scala:871:44 
[error] 871 |      _(fa.use_ !> fb.allocated).map(_.map((fin: F[Unit]) => (_: Resource.ExitCase) => fin)))
[error]     |                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]     |  Found:    F[Unit] => cats.effect.kernel.Resource.ExitCase => F[Unit]
[error]     |  Required: PolyFunction{apply: [t](x$1: t): Any}

Both the inner and outer map calls are implicitly enriched syntax. There's really a lot going on in this and it does need to be minimized, but I wanted to get it up here so we don't lose track of it, especially since this particular file is triggering a lot of compiler bugs for some reason…

Update: Apparently map is available on tuple in Scala 3, but (obviously) not in Scala 2, which thus interferes with the syntax made available by Cats. That's the root of this issue. Leaving the above for posterity. This is definitely going to break quite a bit of code.

joroKr21 commented 3 years ago

I guess the only solution would be to use fmap instead.

djspiewak commented 3 years ago

LOL!