diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-02-04 15:55:59 +0100 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-02-10 10:58:58 -0800 |
commit | 4a8edc03653cb0f6b6ed1cdea1779a19df20f8f5 (patch) | |
tree | a2504af682ddcd74d8050bbf26639b5c58b7c636 /test/pending/pos/t8219.scala | |
parent | b0f81ed35a45fffb9d0761299013d9d5f324ade6 (diff) | |
download | scala-4a8edc03653cb0f6b6ed1cdea1779a19df20f8f5.tar.gz scala-4a8edc03653cb0f6b6ed1cdea1779a19df20f8f5.tar.bz2 scala-4a8edc03653cb0f6b6ed1cdea1779a19df20f8f5.zip |
SI-8129 Make Object#== override Any#==
And the same for !=
If we tried to declare these signatures in non-fictional classes,
we would be chastised about collapsing into the "same signature after
erasure".
This will have an influence of typing, as the typechecking of
arguments is sensitive to overloading: if multiple variants are
feasible, the argument will be typechecked with a wildcard expected
type. So people inspecting the types of the arguments to `==` before
this change might have seen an interesting type for
`if (true) x else y`, but now the `If` will have type `Any`, as we
don't need to calculate the LUB.
I've left a TODO to note that we should really make `Any#{==, !=}`
non-final and include a final override in `AnyVal`. But I don't think
that is particularly urgent.
Diffstat (limited to 'test/pending/pos/t8219.scala')
-rw-r--r-- | test/pending/pos/t8219.scala | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/test/pending/pos/t8219.scala b/test/pending/pos/t8219.scala index 96bf03d316..d55d3139e1 100644 --- a/test/pending/pos/t8219.scala +++ b/test/pending/pos/t8219.scala @@ -8,11 +8,11 @@ class Broken { def in(a: Any) = () in { import scala.None // any import will do.. - "" == "" + "" == "" // no longer a problem, see pos/t8129.scala } - // We fall into the errant code path above because `Any#==` and `AnyRef#==` - // are (currently) overloaded. + // 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 @@ -33,4 +33,17 @@ class Broken { 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("") + } } |