-
Notifications
You must be signed in to change notification settings - Fork 21
Infix sequence wildcard can't match empty sequence in 2.13 (empty multiarg infix not supported) #12110
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
Comments
2.13:
2.12:
First of all I'm surprised that Secondly I'd never seen infix notation for
So My feeling and vote right now is that the code shouldn't've compiled in 2.12, so it's not a bug in 2.13. |
I would say replacing
SLS 8.1.11 is purely syntactical transformation, We use such extractors in Scala plugin to match AST nodes of method invocations. It is very convenient to have a single extractor to work with any number of argument expressions. |
Oh, wow, TIL scala> object Unapplyer { def unapplySeq(seq: Seq[Int]): Option[(Int, Seq[Int])] = if (seq.isEmpty) None else Some((seq.head, seq.tail)) }
object Unapplyer
scala> Seq(1) match { case Unapplyer(value) => value }
val res1: Int = 1 |
FWIW Dotty only seems to support infix notation for binary extractors. So that's only the first kind of infix operation pattern that the spec mentions. |
The expression spec says "several arguments in parens", which excludes n = 0. I don't think the pattern was discussed, but I see attention was paid to the community build to get a sense of whether the obsolete usage was common. |
I wondered if |
@som-snytt I never saw |
Hey, sorry for bumping this thread. This infix style is used heavily in the IntelliJ Scala plugin for extracting values in their ASTs. The Scala plugin for IntelliJ historically was targeting Scala 2.12, and for their latest release they are finally targeting 2.13. Hmm, I just noticed that the OP is an IntelliJ Scala plugin developer who sent the 2.13 PR :) Anyway, I was upgrading my own IntelliJ plugin for ZIO to 2.13 and ran into the same issue. In my case I also had to fix a bunch of:
warnings when using those extractors. Is there an alternative syntax that may be considered? I'd really like the "before" example in the above image to work :) |
Looks at my notes above it looks the other way round? 2.13 is adapting where 2.12 wasn't: 2.13
2.12
If someone could bisect the commit that causes this to no longer work, I could look into seeing whether its reversible or not.
For new syntaxes, you must ask Dotty, on https://contributors.scala-lang.org/. |
To summarize, expression The spec doesn't mention a hypothetical unary case with only one expression, but the language for "multiarg infix" legislates against it (there must be several args). There was an earlier "style" edge case [not in the spec] where Patterns look the same as the corresponding expressions. It's worth noting that In Scala 3:
In Scala 2, the syntax for sequence wildcard means you can't say
Somehow I sense a puzzler coming on in that last example. I will create a feature request on Scala 3 for the infix There was some discussion whether Scala 3 will support "multiarg infix" for expressions, and as noted in a previous comment, it is not supported in patterns. I don't know if that makes "infix sequence wildcard" even less likely. |
Old Scala:
|
Scala 3 post-pandemic:
|
@som-snytt I merged the PR adding tests of the status quo. This may be implicit in what you have already written, but would you mind explicitly stating what the status is here, in both Scala 2 and 3? Did you add the status-quo tests because you believe it's a wontfix for 2.13? Is Scala 3's behavior the same or different than 2.13's? |
This is wontfix for 2.13 despite our wont for fixing things. As @Jasper-M noted, Scala 3 supports only binary The dotty feature request is lampepfl/dotty-feature-requests#144 Innovative solutions should be posted there. Maybe the answer is a spec tweak to give There is an open dotty ticket for "improved" support for multiarg infix expressions: which links to the stalled effort to remove multiarg infix syntax altogether. Maybe also restore expr |
I neglected to commit a test, which I expected to warn under
Dotty is especially obscure because of the tuple:
|
Thank you! |
reproduction steps
Scala version: 2.13.3
problem
The code above can't be compiled with Scala 2.13.
The text was updated successfully, but these errors were encountered: