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
Lint select from Unit
, or Int
that incurs widening
#10372
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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.
long.isNaN
goes throughfloat2Float(long.toFloat)
, notdouble2Double
, so this seems to cover it all.