Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Under -Xsource:3, deprecate infix named args [ci: last-only] #10857

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

Merged
merged 3 commits into from
Nov 5, 2024

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented Sep 6, 2024

In Scala 3.6, named tuples makes Option apply (x = 42) an optional tuple.

Under -Xsource:3, deprecate named args in infix applications (arity one, a single arg).

Demote -Xlint:multiarg-infix to -Wmultiarg-infix, to warn for infix-style applications of arity greater than one. These work the same in Scala 3.6.

Addresses scala/scala3#19072

@scala-jenkins scala-jenkins added this to the 2.13.16 milestone Sep 6, 2024
@som-snytt som-snytt force-pushed the discussion/19072-infix-named-arg branch 2 times, most recently from 380a701 to d360d4f Compare September 7, 2024 04:36
@SethTisue
Copy link
Member

wdyt about only warning under -Xsource:3?

@som-snytt
Copy link
Contributor Author

tired: warn under -Xsource:3

wired: default to -Xsource:3-cross -Werror

The question whether it's worth doing anything on Scala 2 where there is no development branch (nothing can change) made me second-guess whether this is worth doing on Scala 3, so I'll comment on the discussion. I see discussions don't get a link when mentioned.

@som-snytt som-snytt closed this Sep 7, 2024
@SethTisue SethTisue removed this from the 2.13.16 milestone Sep 7, 2024
@som-snytt
Copy link
Contributor Author

Coincidentally scala/scala3#21681 named tuples forces the issue. That got a mention on the discussion (the discussion between myself).

@som-snytt som-snytt reopened this Oct 22, 2024
@scala-jenkins scala-jenkins added this to the 2.13.16 milestone Oct 22, 2024
@som-snytt som-snytt force-pushed the discussion/19072-infix-named-arg branch from d360d4f to cf956f7 Compare October 22, 2024 23:03
@som-snytt som-snytt marked this pull request as ready for review October 22, 2024 23:14
@som-snytt som-snytt changed the title Deprecate infix named args Deprecate infix named args [ci: last-only] Oct 23, 2024
@som-snytt som-snytt force-pushed the discussion/19072-infix-named-arg branch from cf956f7 to 377a937 Compare October 23, 2024 16:33
@som-snytt
Copy link
Contributor Author

Adds -Xsource:3 for the deprecation; demotes -Wmultiarg-infix because it does not warn in Dotty and also does not produce a named tuple, so that it is unlikely to require any messaging ever, but retained as an opt-in warning for anyone who feels strongly about it and doesn't use a DSL that requires it.

@som-snytt som-snytt requested a review from SethTisue October 23, 2024 16:43
@som-snytt
Copy link
Contributor Author

Requesting Seth as a reviewer and cashing in a favor for (e: Unit) syntax.

@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Oct 23, 2024
@som-snytt som-snytt force-pushed the discussion/19072-infix-named-arg branch from 377a937 to a00a0d0 Compare October 23, 2024 20:14
@som-snytt
Copy link
Contributor Author

som-snytt commented Oct 25, 2024

I have to review the last commit, or ask Seth. I just noticed:

importInfos(ctx.unit) ::= (info, keyword, ctx.owner) : @nowarn

where it's taken as a tuple, as intended. So this commit makes the warning opt-in and the nowarn will be unnecessary.

OK, I see 3.5.2 prefers multiarg infix over tupled in the overloaded case. 2.13.15 does the same.

In other words, X op (1, 2, 3) is not syntactically a tuple; the operand is tupled as an adaptation, if necessary.

"How do I warn about that, again?"

➜  ~ scala -Xlint:adapted-args
Welcome to Scala 2.13.15 (OpenJDK 64-Bit Server VM, Java 23).
Type in expressions for evaluation. Or try :help.

scala> def f[A](x: A) = x
def f[A](x: A): A

scala> f(1,2,3)
        ^
       warning: adapted the argument list to the expected 3-tuple: add additional parens instead
               signature: f[A](x: A): A
         given arguments: 1, 2, 3
        after adaptation: f((1, 2, 3): (Int, Int, Int)) [quickfixable]
val res0: (Int, Int, Int) = (1,2,3)

scala> object X { def f[A](x: A) = x.getClass }
object X

scala> X f(1,2,3)
val res1: Class[_ <: (Int, Int, Int)] = class scala.Tuple3

scala>

Aha, it does not warn for the infix syntax!

As a footnote, I remember saying that multiarg infix specifically means multiarg, which is why nilary and unary work correctly; for example, () == (). But by the same token (pun), () op () should be ().op() first and only adapted to ().op(()), and similarly for x op (y). x op (42) is never adapted where Tuple1[A] is expected, which seems wrong.

@som-snytt
Copy link
Contributor Author

I can't delete the @nowarn for multiarg infix on my other PR until this is in; or, I'll just cherry-pick it.

@SethTisue SethTisue removed their assignment Nov 5, 2024
@som-snytt som-snytt merged commit 78bbbbf into scala:2.13.x Nov 5, 2024
3 checks passed
@som-snytt som-snytt deleted the discussion/19072-infix-named-arg branch November 5, 2024 20:40
@SethTisue SethTisue changed the title Deprecate infix named args [ci: last-only] Under -Xsource:3, deprecate infix named args [ci: last-only] Nov 5, 2024
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
Development

Successfully merging this pull request may close these issues.

3 participants