File: Test.scala

package info (click to toggle)
scala 2.11.12-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 62,924 kB
  • sloc: javascript: 28,808; java: 13,415; xml: 3,135; sh: 1,620; python: 756; makefile: 38; awk: 36; ansic: 6
file content (47 lines) | stat: -rw-r--r-- 1,785 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.io.{ByteArrayInputStream, FileOutputStream, BufferedOutputStream}
import java.util

import java.io.File

import scala.tools.partest.DirectTest

object Test extends DirectTest {

  def code = ""

  override def show(): Unit = {

    val class1: Array[Byte] = GroovyInterfaceDump.dump()
    val class2: Array[Byte] = GroovyInterface$1Dump.dump()
    def writeFile(contents: Array[Byte], f: java.io.File): Unit = {
      val out = new BufferedOutputStream(new FileOutputStream(f))
      try {
        out.write(contents)
      } finally out.close()
    }

    val outdir = testOutput.jfile

    // interface GroovyInterface {
    //
    //   // This is the line that causes scalac to choke.
    //   // It results in a GroovyInterface$1 class, which is a non-static inner class but its constructor does not
    //   // include the implicit parameter that is the immediate enclosing instance.
    //   // See http://jira.codehaus.org/browse/GROOVY-7312
    //   //
    //   // Scalac error:
    //   //   [scalac] error: error while loading 1, class file '..../scala_groovy_interop/classes/com/example/groovy/GroovyInterface$1.class' is broken
    //   //   [scalac] (class java.util.NoSuchElementException/head of empty list)
    //   final static def closure = { x -> "banana" }
    //
    // }
    writeFile(GroovyInterfaceDump.dump(), new File(outdir, "GroovyInterface.class"))
    writeFile(GroovyInterface$1Dump.dump(), new File(outdir, "GroovyInterface$1.class"))
    compileCode("object Test { def foo(g: GroovyInterface) = g.toString }")
  }

  def compileCode(code: String) = {
    val classpath = List(sys.props("partest.lib"), testOutput.path) mkString sys.props("path.separator")
    compileString(newCompiler("-cp", classpath, "-d", testOutput.path))(code)
  }
}