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

[backport] Support for Scala 3 syntax under -Xsource:3 #9589

merged 7 commits into from
Apr 23, 2021


Copy link

@smarter smarter commented Apr 22, 2021

This PR backports eee223b from #7660 as well as the following PRs adding support for some Scala 3 syntactic constructs under -Xsource:3:

However, it does not backport the things that -Xsource:3 does in Scala 2.13 which are not syntactic addition (e.g., deprecations, semantic changes for private case classes, semantic changes for contravariant implicit resolution) as well as the leading infix support from #8419

@scala-jenkins scala-jenkins added this to the 2.12.14 milestone Apr 22, 2021
Copy link

Leading infix is syntax.

@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Apr 22, 2021
adriaanm and others added 7 commits April 22, 2021 19:23
Just like in Scala 3.0, adding this keyword doesn't change anything, but
it will be required in future versions of Scala 3 for non-exhaustive
patterns in a for comprehension. We would like to start issuing warnings
by default in Scala 3 for code which does not use `case` in those
situations, but to not hamper cross-compilation we need Scala 2 to also
support that keyword.

For details, see:
Like in Scala 3.0, this allows `?` to be used as a type argument in all
situations where `_` could be used as a wildcard previously. This should
allow us to deprecate the use of `_` as a wildcard in Scala 3 to be able
to eventually repurpose it as explained in

This is a source-breaking change since a type named `?` is legal in
Scala 2 (but not in Scala 3 unless -source 3.0-migration is used).
`?` also has a special meaning when the kind-projector plugin is used,
but that usage has been deprecated in favor of `*` for a while now.
Instead of:

    import foo._

One can now write:

    import foo.*

and instead of:

    import foo.{bar => baz}

One can now write:

    import foo.{bar as baz}

As well as:

    import as baz

This will let us deprecate the old syntax in a future release of Scala
3 (it's currently only deprecated under `-source future`).

for details but note that unlike Scala 3 this commit does not implement
support for:

    import java as j

As that would require deeper changes in the compiler.
Instead of:

    foo(s: _*)

One can now write:


And instead of:

    case Seq(elems @ _*) =>

One can now write:

    case Seq(elems*) =>

for details.
Since everything is open and can be used infix by default in Scala 2,
these keywords are no-op, but they're useful for cross-compiling with a
future version of Scala 3 where they will be required in some
cases (with Scala 3.0 they're only required to avoid warnings under
`-source future`).

for details.
Copy link

@lrytz lrytz left a comment

Choose a reason for hiding this comment

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

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
release-notes worth highlighting in next release notes
None yet
6 participants