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
Discourage multi-argument infix syntax: lint applications (x op (a, b)
), also lint operator-name definitions
#8951
Conversation
Drafting to handle |
77cc387
to
0aad2ab
Compare
Also don't warn on deprecated definitions. Or context bounds: |
Lint multiarg infix applications `x op (a, b, c)` and also method definitions with multiple parameters where the method name is either an operator identifier or a plain identifier ending in an operator character.
For example, `def ?[A: T: U]` may be intended to be invoked `r ?` and not `r ? (t, u)`.
Move the check to typer for owner test.
@lrytz it adds |
The cost is only incurred when warning.
This comment has been minimized.
This comment has been minimized.
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.
Nice work, thank you!
case Parens(args) => mkNamed(args) | ||
case _ => right :: Nil | ||
case Parens(Nil) => literalUnit :: Nil | ||
case Parens(args @ (_ :: Nil)) => mkNamed(args) |
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.
The inner parens are extraneous.
@som-snytt I ran into this case today over in #8998 and it surprised me:
at first I assumed this was just a bug, but now I see it was intentional. but I don't understand the design thinking here? |
@SethTisue I don't know, Seth, but I certainly meant to discourage It did occur to me to go looking in the ecosystem for usages of names with trailing ops. I was too lazy or something.
Edit: Seth is persuasive and convinced me that it shouldn't warn. |
x op (a, b)
), also lint operator-name definitions
This really does not like Slick. It appears that |
Multiarg infix applications are not behind the lint flag, only definitions of multiarg operators (which suggest they would be used infix). It would be friendlier if applications were also behind the lint flag. Edit: scala/bug#12058 |
Lint multiarg infix applications, for example
x op (a, b)
Also lint method definitions with multiple parameters where the method name begins with an operator char, for example
def +(a: Int, b: Int)
, on the assumption that operator-style naming encourages infix at call site.Message in both cases is "multiarg infix syntax looks like a tuple and will be deprecated"
This aligns Scala 2 with Dotty (and likely Scala 3) changes, as per scala/scala3#4311 and http://dotty.epfl.ch/docs/reference/changed-features/operators.html