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

Scala 3 mode with _ as a placeholder and ? as wildcard? #120

Closed
neko-kai opened this issue Sep 24, 2019 · 11 comments · Fixed by #188
Closed

Scala 3 mode with _ as a placeholder and ? as wildcard? #120

neko-kai opened this issue Sep 24, 2019 · 11 comments · Fixed by #188

Comments

@neko-kai
Copy link
Contributor

neko-kai commented Sep 24, 2019

Since dotty/Scala 3 is going to swap the meaning of these two (already does with a flag -source:3.2), would it be possible to support it in kind-projector, to be able to cross-compile Scala 2 / dotty projects with new syntax directly, without going through intermediate * period.

That would be convenient for those projects that are more comfortable making 1 syntax jump right now, instead of 2 syntax jumps in the future.

@SethTisue
Copy link
Member

maybe we can nerd-snipe @martijnhoekstra into this (since he volunteered for #172, and no good deed should go unpunished)

@martijnhoekstra
Copy link
Contributor

dammit Seth

@SethTisue
Copy link
Member

sounds like it's working :-)

@martijnhoekstra
Copy link
Contributor

I'm punting on this one.

@SethTisue
Copy link
Member

maybe someone else watching the repo would like to volunteer...

@neko-kai
Copy link
Contributor Author

neko-kai commented Dec 4, 2020

Is this even technically possible to implement in a compiler plugin? There must've been a reason in the first place to choose the longer ? -> * -> _ hop over a shorter ? -> _ hop

@neko-kai
Copy link
Contributor Author

neko-kai commented Jan 19, 2021

@SethTisue
I've checked and it appears possible to swap the meaning of _ and ?, although it's not as trivial as I hoped due to the wrapping ExistentialTypeTree(...) node that appears once _ is used and must be taken care of.

However, it's not possible to implement +_ and -_ without changing scalac because they're not getting parsed as valid Scala!

[error] kind-projector/src/test/scala/functor.scala:7:56: ']' expected but '_' found.
[error] class EitherRightFunctor[L] extends Functor[Either[L, +_]] {

They're very frequent in my code, so even if a ?->_ swap is merged, without support for variance I wouldn't be able to migrate. Dotty supports some of kind-projector's syntax with -Ykind-projector, maybe it would be a solution to change scalac and add Scala 3.2 type lambda syntax and meaning swap for ?->_ under a flag -source:3.2 or -Ynew-placeholders

@SethTisue
Copy link
Member

@neko-kai I wish I had time to properly think through all your aspects of your suggestion but I don't, so the following is only a partial response.

I can't think of a reason why a scala/scala PR wouldn't be accepted that allowed +_ and -_ through the parser, as long as it also ensures that a later phase gives a comprehensible error (when kind-projector isn't enabled)

In Scala 2, we generally discourage -Y language flags that essentially fork the language, because of the maintenance trouble they cause as well as the trouble they make for tooling authors. But if you can make a case that we should make an exception, we'll listen.

@smarter
Copy link
Contributor

smarter commented Apr 30, 2021

Scala 2.13.6 and 2.12.14 will interpret ? as a wildcard when using the -Xsource:3 flag (cf scala/scala#9560), I've also opened a PR to remove the deprecated support for ? in kind-projector: #186

@neko-kai
Copy link
Contributor Author

neko-kai commented May 3, 2021

@smarter Thanks! This solves one half of the puzzle.
@SethTisue I've opened a PR to allow +_ and -_ through (scala/scala#9605), for now just for the 2.13 branch, I will submit a backport for 2.12 branch if that one gets merged.

@neko-kai
Copy link
Contributor Author

neko-kai commented May 8, 2021

There is now a PR that implements this #188

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants