Skip to content

Commit 702c485

Browse files
committed
Add tests for assignment operator
1 parent cb99f7c commit 702c485

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

tests/neg/warn-value-discard.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@
1414
39 | mutable.Set.empty[String].subtractOne("") // error
1515
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1616
| discarded non-Unit value of type scala.collection.mutable.Set[String]
17+
-- [E172] Potential Issue Error: tests/neg/warn-value-discard.scala:59:4 -----------------------------------------------
18+
59 | mutable.Set.empty[String] += "" // error
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
| discarded non-Unit value of type scala.collection.mutable.Set[String]

tests/neg/warn-value-discard.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,16 @@ class ValueDiscardTest:
5151
// - receiver is a local variable
5252
// --> No warning
5353
field.subtractOne("")
54+
55+
def assignmentOperator(): Unit =
56+
// - += returns this.type
57+
// - receiver is not a field or a local variable
58+
// --> Warning
59+
mutable.Set.empty[String] += "" // error
60+
61+
def assignmentOperatorLocalVariable(): Unit =
62+
// - += returns this.type
63+
// - receiver is a local variable
64+
// --> No warning
65+
val s: mutable.Set[String] = mutable.Set.empty[String]
66+
s += ""

0 commit comments

Comments
 (0)