Skip to content
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

incorrect rewriting of value class == in presence of overloading. #6090

Closed
scabug opened this issue Jul 16, 2012 · 3 comments
Closed

incorrect rewriting of value class == in presence of overloading. #6090

scabug opened this issue Jul 16, 2012 · 3 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Jul 16, 2012

Inspired by #6072:

scala> new V(new X) == new V(new X)
res2: Boolean = false

scala> class X { def ==(other: X) = ??? }
defined class X

scala> class V(val x: X) extends AnyVal
defined class V

scala> new V(new X) == new V(new X)
scala.NotImplementedError: an implementation is missing
	at scala.Predef$.$qmark$qmark$qmark(Predef.scala:243)
	at X.$eq$eq(<console>:8)
	at .<init>(<console>:10)

I'd expect this to dispatch to Any#==.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jul 16, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6090?orig=1
Reporter: @retronym
Affected Versions: 2.10.0
See #6072

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jul 16, 2012

@retronym said:
The potential complementary bug doesn't exist:

scala> class X(val a: Int) extends AnyVal { def ==(other: X) = true }
defined class X

scala> new X(0) == new X(1)
res7: Boolean = true

The tree scrutinized by PostErasureTransformer here is:

  X.this.extension$==(new X(0.$asInstanceOf[Int]()).a().$asInstanceOf[Int](), new X(1.$asInstanceOf[Int]()).a().$asInstanceOf[Int]())

But in any case the match should be modified to replace cmp == nme.EQ || cmp == nme.NE with a symbol based check against Object_== / Object_!=.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jul 21, 2012

@odersky said:
In fact, the behavior is consistent with case classes. Both forward to a method named ==, not necessarily Any_==. I sharpened the test in posterasure according to the suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.