-
Notifications
You must be signed in to change notification settings - Fork 21
Outer check should use equals
rather than eq
in inner class
#11940
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
Comments
This behavior is by-spec. The Since paths are always compared by identity ( |
FYI that corresponds to the spark issues SPARK-2620 and SPARK-9621, that have been biting people for years. (SPARK-2620 was bulk closed with resolution "incomplete" after being open for 5 years, and is still unfixed as of now…) Overriding |
It's also unsound (using a local scala in which I implemented this change): scala> :pa -raw
// Entering paste mode (ctrl-D to finish)
class Outer[T] {
override def equals(that: Any) = that.isInstanceOf[Outer[T]]
case class Foo(x: T)
}
// Exiting paste mode, now interpreting.
scala> val oi = new Outer[Int]; val os = new Outer[String]
oi: Outer[Int] = Outer@68d6f48e
os: Outer[String] = Outer@6c96403e
scala> (oi.Foo(1) : AnyRef) match { case os.Foo(x) => x.length }
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
... 28 elided |
@hrhino It's unsound because the |
Am I understanding correctly that this is happening because spark uses a class-based repl? If so, that sounds like a good reason for not using a class-based repl (I still think that all issues with the object-based repl are solvable: scala/scala3#5135 (comment)). |
What is unsound about my I don't even have to write an case class Outer[T]() {
case class Foo(t: T)
} |
|
For reference, https://www.scala-lang.org/files/archive/spec/2.13/08-pattern-matching.html#type-patterns
|
I think that's true, I don't know / remember why. |
To be able to serialize functions and send them across the network I think. |
It would still be interesting to allow to replace the That would only impact code entered by users in the repl, and only so when the right compiler options are passed. As @smarter said, scala/scala3#5135 (comment) may address that if it gets implemented. But that's if there are no roadblocks down the line, and that's in a more distant future. |
reproduction steps
problem
instancesEqual
is false, even thoughouterReferencesEqual
is true.expectation
instancesEqual
is true.This is related to but not exactly the same problem as #4440 (comment). Here, we don't have the
final
modifier, so we don't run in #4440. The issue here is about the use ofeq
, rather thanequals
, to compare outer references.The text was updated successfully, but these errors were encountered: