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

Discourage multi-argument infix syntax: lint applications (x op (a, b)), also lint operator-name definitions #8951

Merged
merged 6 commits into from May 6, 2020

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented May 3, 2020

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

@scala-jenkins scala-jenkins added this to the 2.13.3 milestone May 3, 2020
@som-snytt som-snytt marked this pull request as draft May 3, 2020 08:56
@som-snytt
Copy link
Contributor Author

Drafting to handle (i, j) == (42, 17).

@som-snytt som-snytt marked this pull request as ready for review May 3, 2020 23:47
@som-snytt som-snytt force-pushed the dev/503 branch 2 times, most recently from 77cc387 to 0aad2ab Compare May 4, 2020 03:17
@som-snytt
Copy link
Contributor Author

som-snytt commented May 4, 2020

Also don't warn on deprecated definitions.

Or context bounds: def ?[T: ru.TypeTag : ClassTag] = InternalInfo[T]

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.
@som-snytt som-snytt requested a review from lrytz May 5, 2020 02:36
@som-snytt
Copy link
Contributor Author

@lrytz it adds -Wconf!

@som-snytt

This comment has been minimized.

Copy link
Member

@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.

Nice work, thank you!

@lrytz lrytz merged commit 9168c33 into scala:2.13.x May 6, 2020
case Parens(args) => mkNamed(args)
case _ => right :: Nil
case Parens(Nil) => literalUnit :: Nil
case Parens(args @ (_ :: Nil)) => mkNamed(args)
Copy link
Contributor Author

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 som-snytt deleted the dev/503 branch May 6, 2020 09:11
@SethTisue SethTisue added the release-notes worth highlighting in next release notes label May 6, 2020
@SethTisue
Copy link
Member

SethTisue commented May 22, 2020

where the method name is [...] a plain identifier ending in an operator character

@som-snytt I ran into this case today over in #8998 and it surprised me:

[error] /Users/tisue/scala.213/src/library/scala/sys/process/ProcessBuilderImpl.scala:139:9: multiarg infix syntax looks like a tuple and will be deprecated
[error]     def lineStream_!(log: ProcessLogger, capacity: Integer): Stream[String] = lineStream(withInput = false, nonZeroException = false, Some(log), capacity)
[error]         ^

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? lineStream_! doesn't seem like a good example of what you meant to discourage? what is a good example of what you mean to discourage?

@som-snytt
Copy link
Contributor Author

som-snytt commented May 22, 2020

@SethTisue I don't know, Seth, but I certainly meant to discourage lineStream_!.

It did occur to me to go looking in the ecosystem for usages of names with trailing ops. I was too lazy or something.

sys.process has a background in funky op names that history has not been kind to, but maybe there are other important use cases besides setter_=.

Edit: Seth is persuasive and convinced me that it shouldn't warn.

@SethTisue SethTisue changed the title Lint multiarg infix operand Discourage multi-argument infix syntax: lint applications (x op (a, b)), also lint operator-name definitions Jun 23, 2020
@jeffrey-aguilera
Copy link

jeffrey-aguilera commented Jun 26, 2020

This really does not like Slick. It appears that scalac -X does not have an entry for -Xlint:multiarg-infix

@som-snytt
Copy link
Contributor Author

som-snytt commented Jun 26, 2020

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

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