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
Endless recursion as a result of incorrect specialization #5629
Comments
Imported From: https://issues.scala-lang.org/browse/SI-5629?orig=1 |
@non said: import scala.{specialized => spec}
trait GrandParent[@spec(Int) -A] {
def foo(a:A): Unit
def bar[B <: A](b:B): Unit = println("grandparent got: %s" format b)
}
trait Parent[@spec(Int) -A] extends GrandParent[A] {
def foo(a:A) = bar(a)
}
class IntChild extends Parent[Int] {
override def bar[B <: Int](b:B): Unit = println("int child got: %s" format b)
}
class AnyChild extends Parent[Any] {
override def bar[B <: Any](b:B): Unit = println("any child got: %s" format b)
}
object Test {
def main(args:Array[String]) {
new IntChild().foo(33)
new AnyChild().foo(33)
}
} The expected output is: int child got: 33
any child got: 33 the actual output is: grandparent got: 33
any child got: 33 |
@non said (edited on Mar 29, 2012 7:42:23 PM UTC): Interestingly, if you remove the type parameters from bar the problem disappears. EDIT: That is not quite right. Really it seems that Grandparent contains a specialized method bar$mcI$sp which Parent$mcI$sp calls. Since IntChild extends Parent$mcI$sp but does not override bar$mcI$sp the grandparent's version is used. |
@non said: |
@pavelpavlov said: |
@non said: I know that after 2.10 there will be some work put into trying to redesign specialization a little bit. So it may be best to just wait and see how that goes. |
@pavelpavlov said: |
@non said: import scala.{specialized => spec}
trait GrandParent[@spec(Int) -A] {
def foo(a:A): Unit
def bar[@spec(Int) B <: A](b:B): Unit = println("grandparent got: %s" format b)
}
trait Parent[@spec(Int) -A] extends GrandParent[A] {
def foo(a:A) = bar(a)
}
class IntChild extends Parent[Int] {
override def bar[@spec(Int) B <: Int](b:B): Unit = println("int child got: %s" format b)
}
class AnyChild extends Parent[Any] {
override def bar[@spec(Int) B <: Any](b:B): Unit = println("any child got: %s" format b)
}
object Test {
def main(args:Array[String]) {
new IntChild().foo(33)
new AnyChild().foo(33)
}
} Pavel, you may want to consider trying this with your code as well. |
@pavelpavlov said: |
@non said: So while the bug is still open, hopefully it won't impede your PF work. |
@non said: It seems clear that you either need to override bar and bar$mcI$sp or neither. The other option would be for the subclass' bar to be automatically specialized, but that seems a bit risky. On the other hand it would certainly be more convenient. Anyone else have any thoughts on this? |
@axel22 said: |
@axel22 said: |
@axel22 said: |
Expected output:
Actual output:
The bug is no longer reproduced when we replace
type T = Int
bytype T = Any
or remove@specialized
.Now this prevents partial functions to be specialized.
The text was updated successfully, but these errors were encountered: