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

scala.reflect.internal.FatalError: package scala does not have a member Int #13

Open
saaivs opened this issue Apr 11, 2015 · 4 comments

Comments

@saaivs
Copy link

saaivs commented Apr 11, 2015

Calling the ScalaScriptEngine.refresh() cause the exception "scala.reflect.internal.FatalError: package scala does not have a member Int"

Env :
Scala: v2.11.4
Playframework v2.3.8

Stack trace:
scala.reflect.internal.FatalError: package scala does not have a member Int
at scala.reflect.internal.Definitions$DefinitionsClass.scala$reflect$internal$Definitions$DefinitionsClass$$fatalMissingSymbol(Definitions.scala:1179)
at scala.reflect.internal.Definitions$DefinitionsClass.getMember(Definitions.scala:1196)
at scala.reflect.internal.Definitions$ValueClassDefinitions$class.valueClassSymbol(Definitions.scala:77)
at scala.reflect.internal.Definitions$ValueClassDefinitions$class.IntClass(Definitions.scala:114)
at scala.reflect.internal.Definitions$DefinitionsClass.IntClass$lzycompute(Definitions.scala:153)
at scala.reflect.internal.Definitions$DefinitionsClass.IntClass(Definitions.scala:153)
at scala.reflect.internal.Definitions$ValueClassDefinitions$class.IntTpe(Definitions.scala:127)
at scala.reflect.internal.Definitions$DefinitionsClass.IntTpe$lzycompute(Definitions.scala:153)
at scala.reflect.internal.Definitions$DefinitionsClass.IntTpe(Definitions.scala:153)
at scala.tools.nsc.symtab.classfile.ClassfileParser.sig2type$1(ClassfileParser.scala:623)
at scala.tools.nsc.symtab.classfile.ClassfileParser.sig2type$1(ClassfileParser.scala:721)
at scala.tools.nsc.symtab.classfile.ClassfileParser.scala$tools$nsc$symtab$classfile$ClassfileParser$$sigToType(ClassfileParser.scala:767)
at scala.tools.nsc.symtab.classfile.ClassfileParser$ConstantPool.getType(ClassfileParser.scala:284)
at scala.tools.nsc.symtab.classfile.ClassfileParser.parseMethod(ClassfileParser.scala:561)
at scala.tools.nsc.symtab.classfile.ClassfileParser.scala$tools$nsc$symtab$classfile$ClassfileParser$$queueLoad$1(ClassfileParser.scala:478)
at scala.tools.nsc.symtab.classfile.ClassfileParser$$anonfun$parseClass$1.apply$mcV$sp(ClassfileParser.scala:488)
at scala.tools.nsc.symtab.classfile.ClassfileParser.parseClass(ClassfileParser.scala:493)
at scala.tools.nsc.symtab.classfile.ClassfileParser.parse(ClassfileParser.scala:134)
at scala.tools.nsc.symtab.SymbolLoaders$ClassfileLoader$$anonfun$doComplete$2.apply$mcV$sp(SymbolLoaders.scala:309)
at scala.tools.nsc.symtab.SymbolLoaders$ClassfileLoader$$anonfun$doComplete$2.apply(SymbolLoaders.scala:309)
at scala.tools.nsc.symtab.SymbolLoaders$ClassfileLoader$$anonfun$doComplete$2.apply(SymbolLoaders.scala:309)
at scala.reflect.internal.SymbolTable.enteringPhase(SymbolTable.scala:235)
at scala.tools.nsc.symtab.SymbolLoaders$ClassfileLoader.doComplete(SymbolLoaders.scala:309)
at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:211)
at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1481)
at scala.reflect.internal.Symbols$Symbol.initialize(Symbols.scala:1628)
at scala.reflect.internal.Definitions$DefinitionsClass.init(Definitions.scala:1387)
at scala.tools.nsc.Global$Run.(Global.scala:1053)
at com.googlecode.scalascriptengine.internals.CompilerManager.acc(CompilerManager.scala:61)
at com.googlecode.scalascriptengine.internals.CompilerManager.(CompilerManager.scala:66)
at com.googlecode.scalascriptengine.ScalaScriptEngine.compileManager(ScalaScriptEngine.scala:44)
at com.googlecode.scalascriptengine.ScalaScriptEngine.refresh(ScalaScriptEngine.scala:95)

@kostaskougios
Copy link
Owner

Hi, I've replied on google groups, https://groups.google.com/forum/#!topic/scala-script-engine/9YteLsdXPKU

@saaivs
Copy link
Author

saaivs commented Apr 11, 2015

Thank you for the reply. Seems like this issue only Play framework applications specific and not depends on the scala version.

@saaivs
Copy link
Author

saaivs commented Apr 11, 2015

Got the issue resolved. Not nice workaround, but working.
The issue is in classpath in projects using Scala and Play Framework 2.
It can be resolved by populating classpath from SBT to the application:

Add to build.sbt file:

val sbtcp = taskKey[Unit]("sbt-classpath")

sbtcp := {
  val files: Seq[File] = (fullClasspath in Compile).value.files
  val sbtClasspath : String = files.map(x => x.getAbsolutePath).mkString(":")
  println("Set SBT classpath to 'sbt-classpath' environment variable")
  System.setProperty("sbt-classpath", sbtClasspath)
}

compile  <<= (compile in Compile).dependsOn(sbtcp)

Code from example:

    // the source directory
    val sourceDir = new File("src")

    val sbtClasspath = System.getProperty("sbt-classpath")
    val classpathSet = sbtClasspath.split(":").map(x => new File(x)).toSet

    // compilation classpath
    val compilationClassPath = classpathSet
    // runtime classpath (empty). All other classes are loaded by the parent classloader
    val runtimeClasspath = ScalaScriptEngine.currentClassPath

    // the output dir for compiled classes
    val outputDir = new File("target")

    val sse = new ScalaScriptEngine(Config(
      List(SourcePath(Set(sourceDir), outputDir)),
      compilationClassPath,
      runtimeClasspath
    )) with RefreshAsynchronously with FromClasspathFirst {
      val recheckEveryMillis: Long = 1000 // each file will only be checked maximum once per second
    }

    // delete all compiled classes (i.e. from previous runs)
    sse.deleteAllClassesInOutputDirectory
    // since the refresh occurs async, we need to do the 1st refresh otherwise initially my.TryMe
    // class will not be found
    sse.refresh

In production should be used another scenario to get a correct classpath.
Probably using a '-cp' or '-classpath' key from the command line.

@sagron
Copy link

sagron commented Feb 16, 2016

I get this same error after upgrading to scala 2.11.7 (standalone w/ sbt 0.13.9 - NOT play) and the workaround did not work. Cause seems to be due to System.getProperty("sbt-classpath") returning null during runtime due to thread scoping. Quick fix is to change line in sbt file from
compile <<= (compile in Compile).dependsOn(sbtcp)
to
run <<= (run in Runtime).dependsOn(sbtcp)

I actually ended up replacing the whole shebang with sclasner
import sclasner.Discoverer
val classpathSet = Discoverer.containers.toSet
Works nicely when building jars with sbt-pack.

Edit: Also had to take out sse.deleteAllClassesInOutputDirectory as it was deleting my non-plugin class files causing the plugin builds to fail when doing an sbt run.

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

No branches or pull requests

3 participants