Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to compile akka-http module with Scala 3 #4091

Merged
merged 2 commits into from Apr 4, 2022

Conversation

jchyb
Copy link
Contributor

@jchyb jchyb commented Mar 31, 2022

This mostly involves specifying types for implicit vals and adding correct parentheses in lambda types. Compilation with -source:3.0-migration was simple, requiring only passing some implicits explicitly in PathDirectives. When I removed the option, another slightly more severe issue popped up, with the compiler seemingly incorrectly inferring types used in javadsl/scaladsl mappings - because of that, the compiler was unable to find the correct implicit. This was fixed by manually specifying types in places like this. What's interesting, this only happened when going through a collection previously converted from java collection (via scala.collections.JavaConverters). This can be for example observed in Rejections.scala.

Nevertheless, now the 'akka-http' module compiles with both 3.1.1, 3.1.2-RC3 and 2.13.8 (2.12.15 errored at the akka-http-core module).

References #4079, task "Enable akka-http module for Scala 3 (currently disabled in Scala 3) and make main code compile"

* "-source:3.0-migration" option was set in sbt
* Added parentheses around lambda type parameters
* Some implicit vals now have a type declared
* Some implicit vals are now passed explicitly
This includes explicitly specyfing the type used for scala/java dsl
mapping methods in lambda functions. There appears to be a problem with
the compiler where their type would be incorrectly infered, leading to
the correct JavaMapping not being found and implicit conversions not
occuring.

Also the ambigousness (as reported by the 3.0-migration
option) of references in RoutingSettings was fixed.

Source 3.0-migration option was removed.
@lightbend-cla-validator

Hi @jchyb,

Thank you for your contribution! We really value the time you've taken to put this together.

Before we proceed with reviewing this pull request, please sign the Lightbend Contributors License Agreement:

https://www.lightbend.com/contribute/cla

@jchyb
Copy link
Contributor Author

jchyb commented Mar 31, 2022

I confirm I signed the Lightbend CLA

Copy link
Member

@jrudolph jrudolph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice first step.

I agree, removing -source:3.0-migration will be some work but it's good enough for me to get something working and incrementally improve on it. Btw. are there any compatibility problems with -source:3.0-migration or will users be able to use the library with and without also setting that flag? (I assume they will get into the same problems as we do when implicit resolution doesn't work quite as it works for Scala 2)

@jchyb
Copy link
Contributor Author

jchyb commented Mar 31, 2022

About the compilation with -source:3.0-migration, I think it should still work for the users (at least the docs do not say otherwise), but it sounds safer to remove it if possible, especially that it usually should not be that difficult. Something that might not have been clear looking at my PR message, I did successfully remove the flag in the second commit of the PR (just for akka-http, not akka-http-core as it seems better to finish implementing parsers there first), it's just that I had to write explicit types in some weird places (likely a bug in the compiler, trying to minimize it now).

@jrudolph jrudolph merged commit 27685a2 into akka:scala-3 Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants