-
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.
Allow discarding "Discarded non-Unit" warnings with
: Unit
Co-Authored-By: nmc.borst <[email protected]> Co-Authored-By: Jędrzej Rochala <[email protected]>
- Loading branch information
1 parent
1947828
commit 46cd256
Showing
15 changed files
with
90 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
-- [E190] Potential Issue Warning: tests/neg/i13091.scala:7:17 --------------------------------------------------------- | ||
7 |def test: Unit = new Foo // error: class Foo is marked @experimental ... | ||
| ^^^^^^^ | ||
| Discarded non-Unit value of type Foo. You may want to use `()`. | ||
-- Error: tests/neg/i13091.scala:7:16 ---------------------------------------------------------------------------------- | ||
7 |def test = (new Foo): Unit // error: class Foo is marked @experimental ... | ||
| ^^^ | ||
| class Foo is marked @experimental | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- Error: tests/neg/i13091.scala:7:21 ---------------------------------------------------------------------------------- | ||
7 |def test: Unit = new Foo // error: class Foo is marked @experimental ... | ||
| ^^^ | ||
| class Foo is marked @experimental | ||
| | ||
| Experimental definition may only be used under experimental mode: | ||
| 1. in a definition marked as @experimental, or | ||
| 2. an experimental feature is imported at the package level, or | ||
| 3. compiling with the -experimental compiler flag. | ||
| Experimental definition may only be used under experimental mode: | ||
| 1. in a definition marked as @experimental, or | ||
| 2. an experimental feature is imported at the package level, or | ||
| 3. compiling with the -experimental compiler flag. |
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
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 |
---|---|---|
|
@@ -10,6 +10,6 @@ object Test: | |
object Test2: | ||
|
||
if true then | ||
1 | ||
() | ||
else 2 // error | ||
|
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,18 @@ | ||
-- [E190] Potential Issue Warning: tests/warn/21557.scala:9:16 --------------------------------------------------------- | ||
9 | val x: Unit = 1 + 1 // warn | ||
| ^^^^^ | ||
| Discarded non-Unit value of type Int. Add `: Unit` to discard silently. | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E176] Potential Issue Warning: tests/warn/21557.scala:10:2 --------------------------------------------------------- | ||
10 | 1 + 1 // warn | ||
| ^^^^^ | ||
| unused value of type (2 : Int) | ||
-- [E175] Potential Issue Warning: tests/warn/21557.scala:15:52 -------------------------------------------------------- | ||
15 | val x1: Unit = new Assertion("another").shouldPass() // warn (enabled by -Wvalue-discard) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| discarded non-Unit value of type Assertion. Add `: Unit` to discard silently. | ||
-- [E176] Potential Issue Warning: tests/warn/21557.scala:16:41 -------------------------------------------------------- | ||
16 | new Assertion("yet another").shouldPass() // warn (enabled by -Wnonunit-statement) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| unused value of type Assertion |
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,19 @@ | ||
//> using options -Wvalue-discard -Wnonunit-statement | ||
|
||
class Assertion(assert: => Any): | ||
def shouldPass(): Assertion = ??? | ||
|
||
def test: Unit = | ||
1 + 1: Unit | ||
(1 + 1): Unit | ||
val x: Unit = 1 + 1 // warn | ||
1 + 1 // warn | ||
val y: Int = 1 + 1 | ||
|
||
new Assertion("").shouldPass(): Unit | ||
(new Assertion("").shouldPass()): Unit | ||
val x1: Unit = new Assertion("another").shouldPass() // warn (enabled by -Wvalue-discard) | ||
new Assertion("yet another").shouldPass() // warn (enabled by -Wnonunit-statement) | ||
val y1: Assertion = new Assertion("another other").shouldPass() | ||
|
||
() |
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 |
---|---|---|
@@ -1,20 +1,20 @@ | ||
-- [E175] Potential Issue Warning: tests/warn/warn-value-discard.scala:27:36 ------------------------------------------- | ||
27 | mutable.Set.empty[String].remove("") // warn | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| discarded non-Unit value of type Boolean | ||
| discarded non-Unit value of type Boolean. Add `: Unit` to discard silently. | ||
-- [E175] Potential Issue Warning: tests/warn/warn-value-discard.scala:39:41 ------------------------------------------- | ||
39 | mutable.Set.empty[String].subtractOne("") // warn | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| discarded non-Unit value of type scala.collection.mutable.Set[String] | ||
| discarded non-Unit value of type scala.collection.mutable.Set[String]. Add `: Unit` to discard silently. | ||
-- [E175] Potential Issue Warning: tests/warn/warn-value-discard.scala:59:4 -------------------------------------------- | ||
59 | mutable.Set.empty[String] += "" // warn | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| discarded non-Unit value of type scala.collection.mutable.Set[String] | ||
| discarded non-Unit value of type scala.collection.mutable.Set[String]. Add `: Unit` to discard silently. | ||
-- [E175] Potential Issue Warning: tests/warn/warn-value-discard.scala:15:35 ------------------------------------------- | ||
15 | firstThing().map(_ => secondThing()) // warn | ||
| ^^^^^^^^^^^^^ | ||
| discarded non-Unit value of type Either[Failed, Unit] | ||
| discarded non-Unit value of type Either[Failed, Unit]. Add `: Unit` to discard silently. | ||
-- [E175] Potential Issue Warning: tests/warn/warn-value-discard.scala:18:35 ------------------------------------------- | ||
18 | firstThing().map(_ => secondThing()) // warn | ||
| ^^^^^^^^^^^^^ | ||
| discarded non-Unit value of type Either[Failed, Unit] | ||
| discarded non-Unit value of type Either[Failed, Unit]. Add `: Unit` to discard silently. |