Warn when named tuples resemble assignments#21823
Conversation
|
My quick test shows an unexpected error for the test in https://github.com/scala/scala3/pull/21565/files |
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 <3648029+nicolasstucki@users.noreply.github.com> Co-Authored-By: Oliver Bračevac <bracevac@users.noreply.github.com>
Co-Authored-By: Nicolas Stucki <3648029+nicolasstucki@users.noreply.github.com> Co-Authored-By: Oliver Bračevac <bracevac@users.noreply.github.com>
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.