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

Typetag and concurrency issues #8929

Closed
scabug opened this issue Oct 20, 2014 · 3 comments
Closed

Typetag and concurrency issues #8929

scabug opened this issue Oct 20, 2014 · 3 comments

Comments

@scabug
Copy link

scabug commented Oct 20, 2014

I have managed to create the following which fails in many ways; stack overflow, class not found and so on.

The code was written to reproduce the essential behaviour seen in scalax.collection.Graph. I'll report it to that group as I think their use of TypeTags is probably ill-advised.

I also suspect that this issue is well-known.

import scala.concurrent._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.reflect.runtime.universe._

sealed trait Bar[E]
trait BarA[E] extends Bar[E]
trait BarB[E] extends Bar[E]
trait Foo[N, E[X] <: Bar[X]] {

// doesn't matter if this is def or val - still fails
implicit val typeTag: TypeTag[E[N]]

@transient lazy val isBar = typeTag.tpe.baseClasses contains typeOf[Bar[_]].typeSymbol
}

case class Thing[N, E[X] <: Bar[X]](t: N)(implicit @transient override val typeTag: TypeTag[E[N]]) extends Foo[N, E]

object TypeTagFail extends App {

val f = future {
ThingString, BarA.isBar
}
f.onSuccess{ case _ ⇒ println("f done") }
f.onFailure{ case e ⇒ println("f failed");e.printStackTrace()}

val g = future {
ThingString, BarB.isBar
}
g.onSuccess{ case _ ⇒ println("g done") }
g.onFailure{ case e ⇒ println("g failed"); e.printStackTrace()}

Await.result(f, 60 seconds)
Await.result(g, 60 seconds)

println("Done")
// wait for stack traces
Thread.sleep(1000)
}

@scabug
Copy link
Author

scabug commented Oct 20, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8929?orig=1
Reporter: Channing Walton (channingwalton)
Affected Versions: 2.10.4
Duplicates #6240

@scabug
Copy link
Author

scabug commented Oct 20, 2014

@xeno-by said:
Yes, that's an unfortunate limitation in how runtime reflection is implemented in 2.10.x. We believe we have fixed this in 2.11.0, but we don't have time to backport the fix to 2.10.5, which means that 2.10.x series will most likely have this as a known issue. Here's a detailed discussion: #6240.

@scabug scabug closed this as completed Oct 20, 2014
@scabug
Copy link
Author

scabug commented Oct 20, 2014

Channing Walton (channingwalton) said:
Thanks, under 2.11 that code seems to work fine under rigorous repeated runs :)

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

2 participants