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

weird use type member which depends on type parameter ends up throwing a ClassCastException #4048

Closed
scabug opened this issue Dec 1, 2010 · 2 comments

Comments

@scabug
Copy link

scabug commented Dec 1, 2010

I'm trying to provide a This type to certain classes which is always the same as the static type of the object we're dealing with, but is more permissive than this.type (which for instance wouldn't let me return a perfect clone of the current object. I cam up with this:

trait Base[+S <: Base[S]] {
  type This = S
  def makeClone: This
}

class Derived0 extends Base[Derived0] {
  def makeClone: This = new Derived0
}

class Derived1 extends Derived0 with Base[Derived1] {
  def derived1Method = ()
}

I would have expected the compiler to complain about the missing makeClone method in Derived1, but it accepts it without a problem. If I then try

val d = new Derived1
d.makeClone.derived1Method

then I get a java.lang.!ClassCastException: Derived0 cannot be cast to Derived1. If I override makeClone in Derived1 to return a new Derived1 instance, it sure works.

Scala: 2.8.1.final
Java: 1.6.0_22
Operating system: Mac OS X 10.6.5

@scabug
Copy link
Author

scabug commented Dec 1, 2010

Imported From: https://issues.scala-lang.org/browse/SI-4048?orig=1
Reporter: Jean-Philippe Pellet (jppellet)

@scabug
Copy link
Author

scabug commented Dec 1, 2010

@paulp said:
This is a duplicate of #3481. It's a pretty serious bug, we should fix it.

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

No branches or pull requests

1 participant