-
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.
Merge pull request #10446 from lrytz/p8120-backport
[backport] Display warning on equals comparing non-references
- Loading branch information
Showing
4 changed files
with
69 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
checksensible-equals.scala:4: warning: comparing values of types Long and Int using `equals` unsafely bypasses cooperative equality; use `==` instead | ||
1L equals 1 | ||
^ | ||
checksensible-equals.scala:11: warning: comparing values of types Any and Int using `equals` unsafely bypasses cooperative equality; use `==` instead | ||
(1L: Any) equals 1 | ||
^ | ||
checksensible-equals.scala:12: warning: comparing values of types AnyVal and Int using `equals` unsafely bypasses cooperative equality; use `==` instead | ||
(1L: AnyVal) equals 1 | ||
^ | ||
checksensible-equals.scala:13: warning: comparing values of types AnyVal and AnyVal using `equals` unsafely bypasses cooperative equality; use `==` instead | ||
(1L: AnyVal) equals (1: AnyVal) | ||
^ | ||
checksensible-equals.scala:16: warning: comparing values of types A and Int using `equals` unsafely bypasses cooperative equality; use `==` instead | ||
def foo[A](a: A) = a.equals(1) | ||
^ | ||
error: No warnings can be incurred under -Xfatal-warnings. | ||
5 warnings found | ||
one error found |
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,19 @@ | ||
// scalac: -Xsource:2.13 -Werror | ||
|
||
class AnyEqualsTest { | ||
1L equals 1 | ||
// ok, because it's between the same numeric types | ||
1 equals 1 | ||
// ok | ||
1L equals "string" | ||
// ok | ||
1L.equals(()) | ||
(1L: Any) equals 1 | ||
(1L: AnyVal) equals 1 | ||
(1L: AnyVal) equals (1: AnyVal) | ||
// ok | ||
"string" equals 1 | ||
def foo[A](a: A) = a.equals(1) | ||
// ok | ||
def bar[A <: AnyRef](a: A) = a.equals(1) | ||
} |