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] Add support for Scala 3 #4124

Open
wants to merge 31 commits into
base: master
Choose a base branch
from

Conversation

djspiewak
Copy link
Contributor

@djspiewak djspiewak commented Dec 30, 2024

Sorry for the massive PR. Scala 3 is a somewhat distressingly large change to the language syntax, as you can see from the kind of invasive surgery I had to perform. Open to bikeshedding on some of the scoping; the constructs themselves are a bit weird (e.g. given and extension), with existing Scala and Haskell probably being the best benchmark. There are a few things I didn't dig into, like for example type matching doesn't use variable scoping where it should (e.g. X match { case Foo[a] => a }, but that's consistent with value-level matching which also doesn't use variable scoping where it should (e.g. x match { case foo: Foo[a] => foo: a }).

One final caveat is I tried to obey the guidance around soft vs hard keywords (extension is a pretty notable example of this), but I just gave up on inline. It can pop up in way too many places so I just made it a hard keyword, even though that's technically over-restrictive.

As an aside, I really wanted to go through and clean up this mode, taking advantage of ambiguous parsing to resolve some of the long-standing annoyances in types and newline inference. This is still probably a good thing to do, but it would be a much larger undertaking and Scala 3 support has been waiting for years at this point, so I figured I'd just cake on the tech debt and we can do a proper mode refactor at a later date.

Anyway, each commit is pretty self-contained, so if you're trying to review things step by step, that's the way to go.

Fixes #2795
Fixes #3778
Closes #3779

@djspiewak
Copy link
Contributor Author

djspiewak commented Dec 30, 2024

Oh one notable bit here…

There's some very old syntax which Scala 3 (and subsequently Scala 2.12 and 2.13) made entirely invalid, which is the following:

x: Int => 42

This type of bare lambda with an explicit type and no parentheses was permitted way back in Scala 2.7, and was even relatively idiomatic, but it's now entirely illegal due to the way that braceless syntax interacts with lambdas. Instead, if you want to write this type of thing, you need to wrap the whole thing in curlies or the formals in parens:

{ x: Int => 42 }
(x: Int) => 42

We have the same problem as scalac in parsing this. In particular, it is ambiguous w.r.t. the following syntax:

foo: a => b

In Scala 3, with braceless syntax, the above can be a valid way of writing the following:

foo { a => b }

…whereas in very old Scala it would be a way of writing this:

{ foo: a => b }

This is why the bare type ascription form was deprecated. So anyone using Sublime with really old versions of Scala (more than a decade at this point) will suddenly see these forms no longer scoping as expected.

@djspiewak djspiewak changed the title Add support for Scala 3 [Scala] Add support for Scala 3 Dec 30, 2024
@jrappen
Copy link
Contributor

jrappen commented Dec 31, 2024

In #3779 you mentioned, this would fix #3778 as well. It's not listed as fixed at the end of your opening comment (i.e. the commit message once this is merged) here, though.


An oversight I assume? Maybe add:

...

Fixes #3778
Closes #3779

@djspiewak
Copy link
Contributor Author

Definitely an oversight. I didn't think about the other issue until after I opened the PR. I'll add a test which shows it's fixed and then add the bit to the description.

Scala/Scala.sublime-syntax Outdated Show resolved Hide resolved
@michaelblyons michaelblyons added T: enhancement Improvement of existing language features significant C: Syntax labels Dec 31, 2024
Copy link
Collaborator

@deathaxe deathaxe left a comment

Choose a reason for hiding this comment

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

Can't say much about Scala specific stuff itself, but left some general suggestions.

Scala/Scala.sublime-syntax Show resolved Hide resolved
Scala/Scala.sublime-syntax Show resolved Hide resolved
Scala/Scala.sublime-syntax Show resolved Hide resolved
Scala/Scala.sublime-syntax Outdated Show resolved Hide resolved
Scala/Scala.sublime-syntax Show resolved Hide resolved
Scala/Scala.sublime-syntax Show resolved Hide resolved
Scala/Scala.sublime-syntax Show resolved Hide resolved
Copy link
Collaborator

@deathaxe deathaxe left a comment

Choose a reason for hiding this comment

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

LGTM!

@deathaxe
Copy link
Collaborator

deathaxe commented Jan 6, 2025

Also adding more meta.group etc. can be done separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: Syntax significant T: enhancement Improvement of existing language features
Projects
None yet
4 participants