-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport "Warn when named tuples resemble assignments" to 3.6 (#21965)
Backports #21823 to the 3.6.2. PR submitted by the release tooling. [skip ci]
- Loading branch information
Showing
13 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
def test1() = | ||
class Person: | ||
def age: Int = ??? | ||
def age_=(x: Int): Unit = ??? | ||
|
||
val person = Person() | ||
|
||
(person.age = 29) // no warn (interpreted as `person.age_=(29)`) | ||
|
||
def test2() = | ||
class Person: | ||
var age: Int = 28 | ||
|
||
val person = Person() | ||
|
||
(person.age = 29) // no warn (interpreted as `person.age_=(29)`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- [E203] Syntax Migration Warning: tests/warn/21681.scala:3:2 --------------------------------------------------------- | ||
3 | (age = 29) // warn | ||
| ^^^^^^^^^^ | ||
| Ambiguous syntax: this is interpreted as a named tuple with one element, | ||
| not as an assignment. | ||
| | ||
| To assign a value, use curly braces: `{age = 29}`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
def main() = | ||
var age: Int = 28 | ||
(age = 29) // warn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- [E203] Syntax Migration Warning: tests/warn/21681b.scala:3:2 -------------------------------------------------------- | ||
3 | (age = 29) // warn | ||
| ^^^^^^^^^^ | ||
| Ambiguous syntax: this is interpreted as a named tuple with one element, | ||
| not as an assignment. | ||
| | ||
| To assign a value, use curly braces: `{age = 29}`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
object Test: | ||
var age: Int = 28 | ||
(age = 29) // warn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- [E203] Syntax Migration Warning: tests/warn/21681c.scala:5:2 -------------------------------------------------------- | ||
5 | (age = 29) // warn | ||
| ^^^^^^^^^^ | ||
| Ambiguous syntax: this is interpreted as a named tuple with one element, | ||
| not as an assignment. | ||
| | ||
| To assign a value, use curly braces: `{age = 29}`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
object Test: | ||
def age: Int = ??? | ||
def age_=(x: Int): Unit = () | ||
age = 29 | ||
(age = 29) // warn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- [E203] Syntax Migration Warning: tests/warn/21770.scala:5:9 --------------------------------------------------------- | ||
5 | f(i => (cache = Some(i))) // warn | ||
| ^^^^^^^^^^^^^^^^^ | ||
| Ambiguous syntax: this is interpreted as a named tuple with one element, | ||
| not as an assignment. | ||
| | ||
| To assign a value, use curly braces: `{cache = Some(i)}`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
def f(g: Int => Unit) = g(0) | ||
|
||
def test = | ||
var cache: Option[Int] = None | ||
f(i => (cache = Some(i))) // warn |