-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Defer warn value discard to refchecks
- Loading branch information
Showing
25 changed files
with
192 additions
and
102 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 |
---|---|---|
@@ -1,6 +1,3 @@ | ||
toughtype.scala:175: warning: multiline expressions might require enclosing parentheses; a value can be silently discarded when Unit is expected | ||
identity[A] _ | ||
^ | ||
toughtype.scala:175: warning: a pure expression does nothing in statement position | ||
toughtype.scala:175: warning: discarded pure expression does nothing | ||
identity[A] _ | ||
^ |
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,12 @@ | ||
discard-advice-a.scala:7: warning: unused value of type scala.concurrent.Future[Int] | ||
Future(42) | ||
^ | ||
discard-advice-a.scala:10: warning: unused value of type scala.concurrent.Future[Int] | ||
Future(42) | ||
^ | ||
discard-advice-a.scala:11: warning: unused value of type Boolean(true) | ||
true | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
3 warnings | ||
1 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,13 @@ | ||
//> using options -Werror -Wnonunit-statement -Wvalue-discard | ||
|
||
import concurrent._, ExecutionContext.Implicits._ | ||
|
||
class C { | ||
def f(): Unit = { | ||
Future(42) | ||
} | ||
def g(): Unit = { | ||
Future(42) | ||
true | ||
} | ||
} |
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 @@ | ||
discard-advice-b.scala:7: warning: discarded non-Unit value of type scala.concurrent.Future[Int] | ||
Future(42) | ||
^ | ||
discard-advice-b.scala:11: warning: discarded non-Unit value of type Boolean(true) | ||
true | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
2 warnings | ||
1 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,13 @@ | ||
//> using options -Werror -Wvalue-discard | ||
|
||
import concurrent._, ExecutionContext.Implicits._ | ||
|
||
class C { | ||
def f(): Unit = { | ||
Future(42) | ||
} | ||
def g(): Unit = { | ||
Future(42) | ||
true | ||
} | ||
} |
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,6 @@ | ||
discard-advice-c.scala:11: warning: discarded pure expression does nothing | ||
true | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
1 warning | ||
1 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,13 @@ | ||
//> using options -Werror | ||
|
||
import concurrent._, ExecutionContext.Implicits._ | ||
|
||
class C { | ||
def f(): Unit = { | ||
Future(42) | ||
} | ||
def g(): Unit = { | ||
Future(42) | ||
true | ||
} | ||
} |
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,15 @@ | ||
discard-advice-d.scala:7: warning: unused value of type scala.concurrent.Future[Int] | ||
Applicable -Wconf / @nowarn filters for this warning: msg=<part of the message>, cat=other-pure-statement, site=C.f | ||
Future(42) | ||
^ | ||
discard-advice-d.scala:10: warning: unused value of type scala.concurrent.Future[Int] | ||
Applicable -Wconf / @nowarn filters for this warning: msg=<part of the message>, cat=other-pure-statement, site=C.g | ||
Future(42) | ||
^ | ||
discard-advice-d.scala:11: warning: unused value of type Boolean(true) | ||
Applicable -Wconf / @nowarn filters for this warning: msg=<part of the message>, cat=other-pure-statement, site=C.g | ||
true | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
3 warnings | ||
1 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,13 @@ | ||
//> using options -Wconf:any:warning-verbose -Werror -Wnonunit-statement -Wvalue-discard | ||
|
||
import concurrent._, ExecutionContext.Implicits._ | ||
|
||
class C { | ||
def f(): Unit = { | ||
Future(42) | ||
} | ||
def g(): Unit = { | ||
Future(42) | ||
true | ||
} | ||
} |
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,21 @@ | ||
t11379a2.scala:9: warning: discarded non-Unit value of type scala.util.Right[Nothing,Unit] | ||
def test1: Either[Int, Unit] = Right(Right(())) | ||
^ | ||
t11379a2.scala:10: warning: discarded non-Unit value of type scala.util.Either[Int,Unit] | ||
def test2: Either[Int, Unit] = Right(()).map(_ => unitRight[Int]) | ||
^ | ||
t11379a2.scala:11: warning: discarded non-Unit value of type scala.util.Either[Int,Unit] | ||
def test3: Either[Int, Unit] = Right(()).map { case _ => unitRight[Int] } | ||
^ | ||
t11379a2.scala:20: warning: discarded non-Unit value of type scala.util.Either[Nothing,Unit] | ||
def test5: Either[Int, Unit] = Right(()).map { case _ => unitRight } | ||
^ | ||
t11379a2.scala:21: warning: discarded non-Unit value of type scala.util.Either[Nothing,Unit] | ||
def test6: Either[Int, Unit] = Right(()).map { _ => unitRight } | ||
^ | ||
t11379a2.scala:22: warning: discarded non-Unit value of type scala.util.Either[Nothing,Unit] | ||
def test7: Either[Int, Unit] = Right(()).map(_ => unitRight) | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
6 warnings | ||
1 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,23 @@ | ||
// scalac: -Werror -Wvalue-discard | ||
object UnitOfTrust { | ||
import scala.util._ | ||
|
||
private def unitRight[A]: Either[A, Unit] = Right(()) | ||
|
||
// fails with: | ||
// discarded non-Unit value | ||
def test1: Either[Int, Unit] = Right(Right(())) | ||
def test2: Either[Int, Unit] = Right(()).map(_ => unitRight[Int]) | ||
def test3: Either[Int, Unit] = Right(()).map { case _ => unitRight[Int] } | ||
|
||
// fails with: | ||
// error: type mismatch; | ||
// found : scala.util.Right[Nothing,Unit] | ||
// required: Unit => Unit | ||
//def test4: Either[Int, Unit] = Right(()).map(Right(())) | ||
|
||
// was: compiles just fine | ||
def test5: Either[Int, Unit] = Right(()).map { case _ => unitRight } | ||
def test6: Either[Int, Unit] = Right(()).map { _ => unitRight } | ||
def test7: Either[Int, Unit] = Right(()).map(_ => unitRight) | ||
} |
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,12 +1,12 @@ | ||
t12495.scala:4: warning: discarded non-Unit value of type (Int, Int) | ||
def g = f(42, 27) | ||
^ | ||
t12495.scala:4: warning: adapted the argument list to expected Unit type: arguments will be discarded | ||
signature: Function1.apply(v1: T1): R | ||
given arguments: 42, 27 | ||
after adaptation: Function1((42, 27): Unit) | ||
def g = f(42, 27) | ||
^ | ||
t12495.scala:4: warning: discarded non-Unit value of type (Int, Int) | ||
def g = f(42, 27) | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
2 warnings | ||
1 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
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,6 +1,3 @@ | ||
contrib674.scala:15: warning: multiline expressions might require enclosing parentheses; a value can be silently discarded when Unit is expected | ||
1 | ||
^ | ||
contrib674.scala:15: warning: a pure expression does nothing in statement position | ||
contrib674.scala:15: warning: discarded pure expression does nothing | ||
1 | ||
^ |
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
Oops, something went wrong.