forked from scala/scala
-
Notifications
You must be signed in to change notification settings - Fork 1
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 scala#3497 from adriaanm/rebase-3464
Make Object#== override Any#==
- Loading branch information
Showing
18 changed files
with
114 additions
and
59 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
t8219-any-any-ref-equals.scala:5: error: method ==: (x$1: Any)Boolean does not take type parameters. | ||
"".==[Int] | ||
^ | ||
t8219-any-any-ref-equals.scala:6: error: method ==: (x$1: Any)Boolean does not take type parameters. | ||
("": AnyRef).==[Int] | ||
^ | ||
t8219-any-any-ref-equals.scala:7: error: method ==: (x$1: Any)Boolean does not take type parameters. | ||
("": Object).==[Int] | ||
^ | ||
three errors 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,8 @@ | ||
object Test { | ||
// The error message tells us that AnyRef#== and Any#== are overloaded. | ||
// A real class couldn't define such an overload, why do we allow AnyRef | ||
// to do so? | ||
"".==[Int] | ||
("": AnyRef).==[Int] | ||
("": Object).==[Int] | ||
} |
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 @@ | ||
trait Equalizer[T] | ||
trait Gen[A] | ||
|
||
class Broken { | ||
implicit def const[T](x: T): Gen[T] = ??? | ||
implicit def convertToEqualizer[T](left: T): Equalizer[T] = ??? | ||
|
||
def in(a: Any) = () | ||
in { | ||
import scala.None // any import will do.. | ||
"" == "" // this no longer triggers the bug, as Object#== now overrides Any#== | ||
} | ||
|
||
// We can still trigger the bug with a structural type, see pending/neg/t8219.scala | ||
} |
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,49 @@ | ||
trait Equalizer[T] | ||
trait Gen[A] | ||
|
||
class Broken { | ||
implicit def const[T](x: T): Gen[T] = ??? | ||
implicit def convertToEqualizer[T](left: T): Equalizer[T] = ??? | ||
|
||
def in(a: Any) = () | ||
in { | ||
import scala.None // any import will do.. | ||
"" == "" // no longer a problem, see pos/t8129.scala | ||
} | ||
|
||
// We used to fall into the errant code path above when `Any#==` and `AnyRef#==` | ||
// were overloaded. | ||
// | ||
// Real classes couldn't get away with that overloading; it would result in | ||
// a compiler error because the variants would collapse into an overriding | ||
// relationship after erasure. | ||
// | ||
// | ||
// But, a structural type can! This triggers the same error, and served as | ||
// a backstop for this test if we change the signatures of `AnyRef#==` to | ||
// override `Any#==`. | ||
type T = { | ||
def a(a: AnyRef): Boolean | ||
def a(a: Any): Boolean | ||
} | ||
|
||
def t: T = ??? | ||
|
||
in { | ||
import scala.None // any import will do.. | ||
t.a("") | ||
} | ||
|
||
// Or, we can get here with ambiguous implicits from the formal parameter | ||
// type of the less specific overload to that of the more specific. | ||
object T { | ||
def foo(a: Any) = true | ||
def foo(a: String) = true | ||
} | ||
in { | ||
import scala.None | ||
implicit def any2str1(a: Any) = "" | ||
implicit def any2str2(a: Any) = "" | ||
T.foo("") | ||
} | ||
} |
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
Oops, something went wrong.