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
Leaving off Array ClassTag causes compiler stack overflow #6685
Comments
Imported From: https://issues.scala-lang.org/browse/SI-6685?orig=1
|
@xeno-by said (edited on Nov 18, 2012 6:12:37 PM UTC): scala> class ArrayUser[A /*: ClassTag*/](initSize:Int) {
| var it: Array[A] = _
| initIt(initSize)
| def initIt(initSize:Int) { it = new Array[A](initSize) }
| }
<console>:29: error: cannot find class tag for element type A
def initIt(initSize:Int) { it = new Array[A](initSize) }
^ Could you please try this in REPL? |
Rows Dower (rowsdower) said: |
@xeno-by said: |
Rows Dower (rowsdower) said (edited on Nov 18, 2012 9:44:38 PM UTC): |
@retronym said (edited on Nov 18, 2012 10:08:08 PM UTC): |
Rows Dower (rowsdower) said: |
@harrah said:
// C.scala
import java.net.{URL, URLClassLoader}
import java.io.File
object C {
final val OutputDirectory = "out"
final val MainClass = "scala.tools.nsc.Main"
final val MainMethod = "main"
def main(args: Array[String]) {
val scalaClasspath = args(0)
val sources = args.drop(1)
val scp = toClasspathArray(scalaClasspath)
mkdir(OutputDirectory)
val cl = new URLClassLoader(scp, null)
val module = getModule(MainClass, cl)
val method = module.getClass.getMethod(MainMethod, classOf[Array[String]])
method.invoke(module, scalacArgs(scalaClasspath, sources.toList).toArray)
}
def scalacArgs(cp: String, sources: List[String]): List[String] =
"-cp" :: cp :: "-d" :: OutputDirectory :: sources
def mkdir(name: String): Unit = (new File(name)).mkdir()
def toClasspathArray(cp: String): Array[URL] =
cp.split(File.pathSeparator).map(s => (new File(s)).toURL).toArray
def getModule(className: String, loader: ClassLoader): Any = {
val obj = Class.forName(className + "$", true, loader)
val singletonField = obj.getField("MODULE$")
singletonField.get(null)
}
} // ArrayUser.scala
import scala.reflect.ClassTag
class ArrayUser[A /*: ClassTag*/](initSize:Int) {
var it: Array[A] = _
initIt(initSize)
def initIt(initSize:Int) { it = new Array[A](initSize) }
} The resulting stack trace looks like:
|
@paulp said: |
@xeno-by said: |
@xeno-by said: |
The compiler runs into an error when a parameterized array is used without a ClassTag.
Adding the ClassTag fixes the problem.
The text was updated successfully, but these errors were encountered: