Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10372 from som-snytt/issue/12728-dubious-selections
Lint select from Unit, or Int that incurs widening
- Loading branch information
Showing
11 changed files
with
268 additions
and
14 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
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,162 @@ | ||
t12728.scala:10: warning: dubious usage of method != with unit value | ||
println(u.!=(x)) | ||
^ | ||
t12728.scala:11: warning: dubious usage of method ## with unit value | ||
println(u.##) | ||
^ | ||
t12728.scala:12: warning: dubious usage of method == with unit value | ||
println(u.==(x)) | ||
^ | ||
t12728.scala:13: warning: dubious usage of method asInstanceOf with unit value | ||
println(u.asInstanceOf[Any]) | ||
^ | ||
t12728.scala:14: warning: dubious usage of method equals with unit value | ||
println(u.equals(x)) | ||
^ | ||
t12728.scala:15: warning: dubious usage of method hashCode with unit value | ||
println(u.hashCode) | ||
^ | ||
t12728.scala:16: warning: dubious usage of method isInstanceOf with unit value | ||
println(u.isInstanceOf[Any]) | ||
^ | ||
t12728.scala:17: warning: dubious usage of method toString with unit value | ||
println(u.toString) | ||
^ | ||
t12728.scala:20: warning: Widening conversion from Int to Float is deprecated because it loses precision. Write `.toFloat` instead. | ||
println(i.isNaN) | ||
^ | ||
t12728.scala:20: warning: dubious usage of method isNaN with integer value | ||
println(i.isNaN) | ||
^ | ||
t12728.scala:21: warning: Widening conversion from Int to Float is deprecated because it loses precision. Write `.toFloat` instead. | ||
println(i.isInfinity) | ||
^ | ||
t12728.scala:21: warning: dubious usage of method isInfinity with integer value | ||
println(i.isInfinity) | ||
^ | ||
t12728.scala:22: warning: Widening conversion from Int to Float is deprecated because it loses precision. Write `.toFloat` instead. | ||
println(i.isInfinite) | ||
^ | ||
t12728.scala:22: warning: dubious usage of method isInfinite with integer value | ||
println(i.isInfinite) | ||
^ | ||
t12728.scala:23: warning: Widening conversion from Int to Float is deprecated because it loses precision. Write `.toFloat` instead. | ||
println(i.isFinite) | ||
^ | ||
t12728.scala:23: warning: dubious usage of method isFinite with integer value | ||
println(i.isFinite) | ||
^ | ||
t12728.scala:24: warning: Widening conversion from Int to Float is deprecated because it loses precision. Write `.toFloat` instead. | ||
println(i.isPosInfinity) | ||
^ | ||
t12728.scala:24: warning: dubious usage of method isPosInfinity with integer value | ||
println(i.isPosInfinity) | ||
^ | ||
t12728.scala:25: warning: Widening conversion from Int to Float is deprecated because it loses precision. Write `.toFloat` instead. | ||
println(i.isNegInfinity) | ||
^ | ||
t12728.scala:25: warning: dubious usage of method isNegInfinity with integer value | ||
println(i.isNegInfinity) | ||
^ | ||
t12728.scala:27: warning: Widening conversion from Int to Float is deprecated because it loses precision. Write `.toFloat` instead. | ||
println(i.ceil) | ||
^ | ||
t12728.scala:27: warning: dubious usage of method ceil with integer value | ||
println(i.ceil) | ||
^ | ||
t12728.scala:28: warning: Widening conversion from Int to Float is deprecated because it loses precision. Write `.toFloat` instead. | ||
println(i.floor) | ||
^ | ||
t12728.scala:28: warning: dubious usage of method floor with integer value | ||
println(i.floor) | ||
^ | ||
t12728.scala:30: warning: Widening conversion from Long to Float is deprecated because it loses precision. Write `.toFloat` instead. | ||
println(l.isNaN) | ||
^ | ||
t12728.scala:30: warning: dubious usage of method isNaN with integer value | ||
println(l.isNaN) | ||
^ | ||
t12728.scala:31: warning: Widening conversion from Long to Float is deprecated because it loses precision. Write `.toFloat` instead. | ||
println(l.isInfinity) | ||
^ | ||
t12728.scala:31: warning: dubious usage of method isInfinity with integer value | ||
println(l.isInfinity) | ||
^ | ||
t12728.scala:32: warning: Widening conversion from Long to Float is deprecated because it loses precision. Write `.toFloat` instead. | ||
println(l.isInfinite) | ||
^ | ||
t12728.scala:32: warning: dubious usage of method isInfinite with integer value | ||
println(l.isInfinite) | ||
^ | ||
t12728.scala:33: warning: Widening conversion from Long to Float is deprecated because it loses precision. Write `.toFloat` instead. | ||
println(l.isFinite) | ||
^ | ||
t12728.scala:33: warning: dubious usage of method isFinite with integer value | ||
println(l.isFinite) | ||
^ | ||
t12728.scala:34: warning: Widening conversion from Long to Float is deprecated because it loses precision. Write `.toFloat` instead. | ||
println(l.isPosInfinity) | ||
^ | ||
t12728.scala:34: warning: dubious usage of method isPosInfinity with integer value | ||
println(l.isPosInfinity) | ||
^ | ||
t12728.scala:35: warning: Widening conversion from Long to Float is deprecated because it loses precision. Write `.toFloat` instead. | ||
println(l.isNegInfinity) | ||
^ | ||
t12728.scala:35: warning: dubious usage of method isNegInfinity with integer value | ||
println(l.isNegInfinity) | ||
^ | ||
t12728.scala:37: warning: Widening conversion from Long to Float is deprecated because it loses precision. Write `.toFloat` instead. | ||
println(l.ceil) | ||
^ | ||
t12728.scala:37: warning: dubious usage of method ceil with integer value | ||
println(l.ceil) | ||
^ | ||
t12728.scala:38: warning: Widening conversion from Long to Float is deprecated because it loses precision. Write `.toFloat` instead. | ||
println(l.floor) | ||
^ | ||
t12728.scala:38: warning: dubious usage of method floor with integer value | ||
println(l.floor) | ||
^ | ||
t12728.scala:40: warning: dubious usage of method isNaN with integer value | ||
println(c.isNaN) | ||
^ | ||
t12728.scala:41: warning: dubious usage of method isInfinity with integer value | ||
println(c.isInfinity) | ||
^ | ||
t12728.scala:42: warning: dubious usage of method isInfinite with integer value | ||
println(c.isInfinite) | ||
^ | ||
t12728.scala:43: warning: dubious usage of method isFinite with integer value | ||
println(c.isFinite) | ||
^ | ||
t12728.scala:44: warning: dubious usage of method isPosInfinity with integer value | ||
println(c.isPosInfinity) | ||
^ | ||
t12728.scala:45: warning: dubious usage of method isNegInfinity with integer value | ||
println(c.isNegInfinity) | ||
^ | ||
t12728.scala:47: warning: dubious usage of method ceil with integer value | ||
println(c.ceil) | ||
^ | ||
t12728.scala:48: warning: dubious usage of method floor with integer value | ||
println(c.floor) | ||
^ | ||
t12728.scala:54: warning: dubious usage of method toString with unit value | ||
def g = new java.lang.StringBuilder("hi").setCharAt(0, 'H').toString // "()" | ||
^ | ||
t12728.scala:14: warning: comparing values of types Unit and Any using `equals` unsafely bypasses cooperative equality; use `==` instead | ||
println(u.equals(x)) | ||
^ | ||
t12728.scala:26: warning: method round in class RichInt is deprecated (since 2.11.0): this is an integer type; there is no reason to round it. Perhaps you meant to call this on a floating-point value? | ||
println(i.round) | ||
^ | ||
t12728.scala:36: warning: method round in class RichLong is deprecated (since 2.11.0): this is an integer type; there is no reason to round it. Perhaps you meant to call this on a floating-point value? | ||
println(l.round) | ||
^ | ||
t12728.scala:46: warning: method round in class RichInt is deprecated (since 2.11.0): this is an integer type; there is no reason to round it. Perhaps you meant to call this on a floating-point value? | ||
println(c.round) | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
53 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,55 @@ | ||
// scalac: -Werror -Xlint | ||
|
||
class C { | ||
val u = () | ||
val i = 42 | ||
val l = 42L | ||
val c = 'c' | ||
val x = null: Any | ||
|
||
println(u.!=(x)) | ||
println(u.##) | ||
println(u.==(x)) | ||
println(u.asInstanceOf[Any]) | ||
println(u.equals(x)) | ||
println(u.hashCode) | ||
println(u.isInstanceOf[Any]) | ||
println(u.toString) | ||
println(i.toString) | ||
|
||
println(i.isNaN) | ||
println(i.isInfinity) | ||
println(i.isInfinite) | ||
println(i.isFinite) | ||
println(i.isPosInfinity) | ||
println(i.isNegInfinity) | ||
println(i.round) | ||
println(i.ceil) | ||
println(i.floor) | ||
|
||
println(l.isNaN) | ||
println(l.isInfinity) | ||
println(l.isInfinite) | ||
println(l.isFinite) | ||
println(l.isPosInfinity) | ||
println(l.isNegInfinity) | ||
println(l.round) | ||
println(l.ceil) | ||
println(l.floor) | ||
|
||
println(c.isNaN) | ||
println(c.isInfinity) | ||
println(c.isInfinite) | ||
println(c.isFinite) | ||
println(c.isPosInfinity) | ||
println(c.isNegInfinity) | ||
println(c.round) | ||
println(c.ceil) | ||
println(c.floor) | ||
} | ||
|
||
class UseCase { | ||
def f = new scala.StringBuilder("hi").setCharAt(0, 'H').toString // "Hi" | ||
|
||
def g = new java.lang.StringBuilder("hi").setCharAt(0, 'H').toString // "()" | ||
} |
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,11 @@ | ||
// javaVersion: 11+ | ||
// | ||
// skalac: --release:8 | ||
// trivial manual test for partest --realeasy, which sets --release:8. | ||
// under --realeasy, skip this test because of the javaVersion, irrespective of JDK in use. | ||
// otherwise, this test passes trivially on JDK11+ and is skipped on lesser JDKs. | ||
// note that explicit --release:8 asks to compile against JDK8 but only run on the requested version. | ||
|
||
object Test extends App { | ||
assert("".isBlank) // String#isBlank was added in JDK11 | ||
} |
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