-
Notifications
You must be signed in to change notification settings - Fork 591
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
base: master
Are you sure you want to change the base?
Conversation
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. |
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. |
There was a problem hiding this 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.
Co-authored-by: deathaxe <[email protected]>
Co-authored-by: deathaxe <[email protected]>
Co-authored-by: deathaxe <[email protected]>
Co-authored-by: deathaxe <[email protected]>
Co-authored-by: deathaxe <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Also adding more |
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
andextension
), 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 usevariable
scoping where it should (e.g.X match { case Foo[a] => a }
, but that's consistent with value-level matching which also doesn't usevariable
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 oninline
. 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