-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Improve message for discarded pure non-Unit values #18723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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` | ||
-- [E190] 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 | ||
| | ||
| longer explanation available when compiling with `-explain` |
This file contains hidden or 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 hidden or 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` | ||
-- [E190] 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 | ||
| | ||
| longer explanation available when compiling with `-explain` |
This file contains hidden or 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 hidden or 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` | ||
-- [E190] 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 | ||
| | ||
| longer explanation available when compiling with `-explain` |
This file contains hidden or 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 hidden or 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 @@ | ||
-- [E190] 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 `()`. | ||
--------------------------------------------------------------------------------------------------------------------- | ||
-- [E190] 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 `()`. | ||
--------------------------------------------------------------------------------------------------------------------- | ||
-- [E190] 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 `()`. | ||
--------------------------------------------------------------------------------------------------------------------- | ||
-- [E190] 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one might not be correct. I will double check it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is correct. Class
Foo
has a pure constructor.