-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Warn when named tuples resemble assignments #21823
Conversation
My quick test shows an unexpected error
for the test in |
def f = 42 + (x = 1) -- [E134] Type Error: playground.scala:1:11 ------------------------------------
1 |def f = 42 + (x = 1)
| ^^^^
| None of the overloaded alternatives of method + in class Int with types
| (x: Double): Double
| (x: Float): Float
| (x: Long): Long
| (x: Int): Int
| (x: Char): Int
| (x: Short): Int
| (x: Byte): Int
| (x: String): String
| match arguments ((x : Int)) It is expected to have an error in this case, isn't it? I also get in on We should add a warning to tell the user that |
Also, we found that our naive use of It doesn't work for example for: object Test:
var age: Int = 28
(age = 29) // warn @nicolasstucki suggests that we move our check to |
44708ec
to
dd22105
Compare
@nicolasstucki @bracevac I moved the check to I then tried to type the whole thing as |
I hit this issue in my own code just this morning, during a 3.6.1 upgrade — locating the cause took me a while, so I’m glad to see a warning being added |
Can you add a test for #21770 as well? def f(g: Int => Unit) = g(0)
def test =
var cache: Option[Int] = None
f(i => (cache = Some(i))) Thanks! |
Done. |
Co-Authored-By: Nicolas Stucki <[email protected]> Co-Authored-By: Oliver Bračevac <[email protected]>
Co-Authored-By: Nicolas Stucki <[email protected]> Co-Authored-By: Oliver Bračevac <[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
Backports #21823 to the 3.6.2. PR submitted by the release tooling. [skip ci]
Resolves #22042 * Reverts most of the stabilization changes introduced in #21680 excluding bugfixes introduced when stabilizing the name tuples * Adapts #21823 and #21949 warnings to make them both syntax deprecations instead of ambiguous syntax. * Adds automatic rewrite to #21823 to replace `(foo = bar)` into `{foo = bar}`
This PR adds a warning for named tuples that look like assignment, such as
(x = 1)
.This is the first half to implement #21681. The second will be to add warnings for named arguments to infix method calls (as a separate PR?).
Started during the Spree of October 21st.
Closes #21770.