forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve message for discarded pure non-Unit values
Fixes scala#18408 Fixes scala#18722
- Loading branch information
1 parent
3e105f2
commit a057274
Showing
14 changed files
with
152 additions
and
20 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,18 @@ | ||
-- [E103] Syntax Error: tests/neg/i18408a.scala:2:0 -------------------------------------------------------------------- | ||
2 |fa(42) // error | ||
|^^ | ||
|Illegal start of toplevel definition | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E189] Potential Issue Warning: tests/neg/i18408a.scala:3:15 -------------------------------------------------------- | ||
3 |def test1 = fa(42) | ||
| ^^ | ||
| Discarded non-Unit value of type Int. You may want to use `()`. | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E129] Potential Issue Warning: tests/neg/i18408a.scala:4:16 -------------------------------------------------------- | ||
4 |def test2 = fa({42; ()}) | ||
| ^^ | ||
| A pure expression does nothing in statement position; you may be omitting necessary parentheses | ||
| | ||
| longer explanation available when compiling with `-explain` |
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,4 @@ | ||
def fa(f: String ?=> Unit): Unit = ??? | ||
fa(42) // error | ||
def test1 = fa(42) | ||
def test2 = fa({42; ()}) |
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 @@ | ||
-- [E103] Syntax Error: tests/neg/i18408b.scala:2:0 -------------------------------------------------------------------- | ||
2 |fa(42) // error | ||
|^^ | ||
|Illegal start of toplevel definition | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E189] Potential Issue Warning: tests/neg/i18408b.scala:3:15 -------------------------------------------------------- | ||
3 |def test1 = fa(42) | ||
| ^^ | ||
| Discarded non-Unit value of type Int. You may want to use `()`. | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E129] Potential Issue Warning: tests/neg/i18408b.scala:4:16 -------------------------------------------------------- | ||
4 |def test2 = fa({42; ()}) | ||
| ^^ | ||
| A pure expression does nothing in statement position; you may be omitting necessary parentheses | ||
| | ||
| longer explanation available when compiling with `-explain` |
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,4 @@ | ||
def fa(f: => Unit): Unit = ??? | ||
fa(42) // error | ||
def test1 = fa(42) | ||
def test2 = fa({42; ()}) |
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 @@ | ||
-- [E103] Syntax Error: tests/neg/i18408c.scala:2:0 -------------------------------------------------------------------- | ||
2 |fa(42) // error | ||
|^^ | ||
|Illegal start of toplevel definition | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E189] Potential Issue Warning: tests/neg/i18408c.scala:3:15 -------------------------------------------------------- | ||
3 |def test1 = fa(42) | ||
| ^^ | ||
| Discarded non-Unit value of type Int. You may want to use `()`. | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E129] Potential Issue Warning: tests/neg/i18408c.scala:4:16 -------------------------------------------------------- | ||
4 |def test2 = fa({42; ()}) | ||
| ^^ | ||
| A pure expression does nothing in statement position; you may be omitting necessary parentheses | ||
| | ||
| longer explanation available when compiling with `-explain` |
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,4 @@ | ||
def fa(f: Unit): Unit = ??? | ||
fa(42) // error | ||
def test1 = fa(42) | ||
def test2 = fa({42; ()}) |
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,44 @@ | ||
-- [E189] Potential Issue Error: tests/neg/i18722.scala:3:15 ----------------------------------------------------------- | ||
3 |def f1: Unit = null // error | ||
| ^^^^ | ||
| Discarded non-Unit value of type Null. You may want to use `()`. | ||
|--------------------------------------------------------------------------------------------------------------------- | ||
| Explanation (enabled by `-explain`) | ||
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| As this expression is not of type Unit, it is desugared into `{ null; () }`. | ||
| Here the `null` expression is a pure statement that can be discarded. | ||
| Therefore the expression is effectively equivalent to `()`. | ||
--------------------------------------------------------------------------------------------------------------------- | ||
-- [E189] Potential Issue Error: tests/neg/i18722.scala:4:15 ----------------------------------------------------------- | ||
4 |def f2: Unit = 1 // error | ||
| ^ | ||
| Discarded non-Unit value of type Int. You may want to use `()`. | ||
|--------------------------------------------------------------------------------------------------------------------- | ||
| Explanation (enabled by `-explain`) | ||
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| As this expression is not of type Unit, it is desugared into `{ 1; () }`. | ||
| Here the `1` expression is a pure statement that can be discarded. | ||
| Therefore the expression is effectively equivalent to `()`. | ||
--------------------------------------------------------------------------------------------------------------------- | ||
-- [E189] Potential Issue Error: tests/neg/i18722.scala:5:15 ----------------------------------------------------------- | ||
5 |def f3: Unit = "a" // error | ||
| ^^^ | ||
| Discarded non-Unit value of type String. You may want to use `()`. | ||
|--------------------------------------------------------------------------------------------------------------------- | ||
| Explanation (enabled by `-explain`) | ||
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| As this expression is not of type Unit, it is desugared into `{ "a"; () }`. | ||
| Here the `"a"` expression is a pure statement that can be discarded. | ||
| Therefore the expression is effectively equivalent to `()`. | ||
--------------------------------------------------------------------------------------------------------------------- | ||
-- [E189] Potential Issue Error: tests/neg/i18722.scala:7:15 ----------------------------------------------------------- | ||
7 |def f4: Unit = i // error | ||
| ^ | ||
| Discarded non-Unit value of type Int. You may want to use `()`. | ||
|--------------------------------------------------------------------------------------------------------------------- | ||
| Explanation (enabled by `-explain`) | ||
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| As this expression is not of type Unit, it is desugared into `{ i; () }`. | ||
| Here the `i` expression is a pure statement that can be discarded. | ||
| Therefore the expression is effectively equivalent to `()`. | ||
--------------------------------------------------------------------------------------------------------------------- |
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,9 @@ | ||
//> using options -Werror -explain | ||
|
||
def f1: Unit = null // error | ||
def f2: Unit = 1 // error | ||
def f3: Unit = "a" // error | ||
val i: Int = 1 | ||
def f4: Unit = i // error | ||
val u: Unit = () | ||
def f5: Unit = u |
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