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

@specialized breaks super.overriddenMethod, causing infinite loop and StackOverflowError. #3651

Open
scabug opened this issue Jul 7, 2010 · 7 comments

Comments

@scabug
Copy link

scabug commented Jul 7, 2010

Here is a small example on how to replicate the problem:

object Main {
  def main(args: Array[String]) {
    val s = new Extended("s")
    println(s.foo) //works

    val i = new Extended(1)
    println(i.foo) //infinite loop with StackOverflowError
  }
}

class Base[@specialized(Int) T](val t: T) { def foo() :T = t }
class Extended [@specialized(Int) T](t: T) extends Base[T](t) {
  override def foo() :T = super.foo
}

Tested on Scala.2.8.0.RC7

@scabug
Copy link
Author

scabug commented Jul 7, 2010

Imported From: https://issues.scala-lang.org/browse/SI-3651?orig=1
Reporter: @lexn82
Affected Versions: 2.11.7

@scabug
Copy link
Author

scabug commented Jan 4, 2011

@dragos said:
(In r23892) Fixed infinite loop on call to super from a specialized method. This happened only on illegal specialized inheritance. Closes #3651, no review.

@scabug
Copy link
Author

scabug commented Feb 19, 2011

Lukas Pustina (lukas.pustina) said:
This bug seems to be still present in Scala 2.8.1 -- see below. After discussing on the user-mailinglist, it seems to be necessary to reopen this ticket

Welcome to Scala version 2.8.1.final (Java HotSpot(TM) Client VM, Java 1.6.0_22).
Type in expressions to have them evaluated.
Type :help for more information.

scala> class Klass[@specialized A]( val a: A )
defined class Klass

scala> case class LongKlass( override val a: Long ) extends Klass[Long](a)
defined class LongKlass

scala> LongKlass(10)
java.lang.StackOverflowError
	at Klass$$mcL$$sp.a(<console>:5)
	at LongKlass.a$$mcL$$sp(<console>:6)
	at Klass$$mcL$$sp.a(<console>:5)
	at LongKlass.a$$mcL$$sp(<console>:6)
	at Klass$$mcL$$sp.a(<console>:5)
	at LongKlass.a$$mcL$$sp(<console>:6)
	at Klass$$mcL$$sp.a(<console>:5)
	at LongKlass.a$$mcL$$sp(<console>:6)
	at Klass$$mcL$$sp.a(<console>:5)
	at LongKlass.a$$mcL$$sp(<console>:6)
	at Klass$$mcL$$sp.a(<console>:5)
	at LongKlass.a$$mcL$$sp(<console>:6)
	at Klass$$mcL$$sp.a(<console>:5)
	at LongKlass.a$$mcL$$sp(<console>:6)
	at Klass$$mcL$$sp.a(<console>:5)
	at LongKlass.a$$mcL$$sp(<console>:6)
	at Klass$$mcL$$sp.a(<console>:5)
	at LongKlass.a$$mcL$$sp(<console>:6)
	at Klass$$mcL$$sp.a(<console>:5)
	at LongKlass.a$$mcL$$sp(<console>:6)
	at Klass$$mcL$$sp.a(<console>:5)
	at LongKlass.a$$mcL$$sp(<console>:6)
	at Klass$$mcL$$sp.a(<...

@scabug
Copy link
Author

scabug commented Feb 19, 2011

@ijuma said:
The fix was committed 7 weeks ago. 2.8.1 was released on the 9th of November. What made you believe that this fix was included in 2.8.1?

@scabug
Copy link
Author

scabug commented Feb 19, 2011

Lukas Pustina (lukas.pustina) said:
Replying to [comment:8 ijuma]:

The fix was committed 7 weeks ago. 2.8.1 was released on the 9th of November. What made you believe that this fix was included in 2.8.1?

Sorry, wrong copy&paste -- I just pasted my email to list and not my test against 2.9.0.latest as of today:

Welcome to Scala version 2.9.0.r24304-b20110219020045 (Java HotSpot(TM) Client VM, Java 1.6.0_22).
Type in expressions to have them evaluated.
Type :help for more information.

scala> class Klass[@specialized A]( val a: A )
defined class Klass

scala> case class LongKlass( override val a: Long ) extends Klass[Long](a)
defined class LongKlass

scala> LongKlass(10)
java.lang.StackOverflowError
	at Klass$$mcJ$$sp.a(<console>:7)
	at LongKlass.a$$mcJ$$sp(<console>:8)
	at Klass$$mcJ$$sp.a(<console>:7)
	at LongKlass.a$$mcJ$$sp(<console>:8)
	at Klass$$mcJ$$sp.a(<console>:7)
	at LongKlass.a$$mcJ$$sp(<console>:8)
.....

@scabug
Copy link
Author

scabug commented Mar 4, 2011

@paulp said:
Fixed in r24379.

@scabug
Copy link
Author

scabug commented Nov 30, 2015

Marcin Mościcki (mmoscicki) said:
While the original code works, a longer chain doesn't - unless I'm doing something prohibited:

	trait Root[@specialized(Int) T] {
		def hello(v :T) = "root"
	}

	trait Child[@specialized(Int) T] extends Root[T] {
		override def hello(v :T) = super.hello(v)
	}

	class C[@specialized(Int) T] extends Child[T]

	(new C).hello(1)

Stack overflow:

	at pl.proplus.collection.SpecializationSpec$C$mcI$sp.super$hello$mcI$sp(SpecializationSpec.scala:30)
	at pl.proplus.collection.SpecializationSpec$Child$mcI$sp$class.hello$mcI$sp(SpecializationSpec.scala:20)
	at pl.proplus.collection.SpecializationSpec$C$mcI$sp.hello$mcI$sp(SpecializationSpec.scala:30)

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

3 participants