From 4529141cc154a9d7359e16344d7a318ca529f89f Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 29 Sep 2011 12:45:53 +0000 Subject: Following Paul's detective work, fixed Java cla... Following Paul's detective work, fixed Java class loading in reflection. Moved test code.scala into checkin build. Yay! --- .../scala/reflect/runtime/JavaToScala.scala | 2 +- test/disabled/run/code.scala | 52 ---------------------- test/files/run/code.check | 18 ++++++++ test/files/run/code.scala | 52 ++++++++++++++++++++++ 4 files changed, 71 insertions(+), 53 deletions(-) delete mode 100644 test/disabled/run/code.scala create mode 100644 test/files/run/code.check create mode 100644 test/files/run/code.scala diff --git a/src/compiler/scala/reflect/runtime/JavaToScala.scala b/src/compiler/scala/reflect/runtime/JavaToScala.scala index 3d295e3ff9..f1eedbcf30 100644 --- a/src/compiler/scala/reflect/runtime/JavaToScala.scala +++ b/src/compiler/scala/reflect/runtime/JavaToScala.scala @@ -36,7 +36,7 @@ trait JavaToScala extends ConversionUtil { self: SymbolTable => * Can you check with your newly acquired classloader fu whether this implementation makes sense? */ def javaClass(path: String): jClass[_] = - jClass.forName(path, false, java.lang.ClassLoader.getSystemClassLoader) + jClass.forName(path, false, getClass.getClassLoader) /** Does `path` correspond to a Java class with that fully qualified name? */ def isJavaClass(path: String): Boolean = diff --git a/test/disabled/run/code.scala b/test/disabled/run/code.scala deleted file mode 100644 index 8881c2eda8..0000000000 --- a/test/disabled/run/code.scala +++ /dev/null @@ -1,52 +0,0 @@ -import scala.tools.partest.utils.CodeTest - -case class Element(name: String) - -object Test extends App { - case class InnerElement(name: String) - def foo[T](ys: List[T]) = { - val fun: reflect.Code[Int => Int] = x => x + ys.length - fun - } - CodeTest(foo(List(2)), args) - CodeTest({() => val e = Element("someName"); e}, args) -// CodeTest({() => val e = InnerElement("someName"); e}, args) // (does not work yet) - def titi() = { - var truc = 0 - CodeTest(() => { - truc = 6 - }, args) - } - def tata(): Unit = { - var truc = 0 - CodeTest(() => { - truc = truc + 6 - }, args) - } - titi() - tata() - new baz.A(args) - - def show() { - def foo[T](ys: List[T]) = { - val fun: reflect.Code[Int => Int] = x => x + ys.length - CodeTest(fun, args) - } - foo(List(1, 2, 3)) - } - - show() -} - -package baz { - - case class BazElement(name: String) { } - - class A(args: Array[String]) { - CodeTest(() => new baz.BazElement("someName"), args) - } - -} - - - diff --git a/test/files/run/code.check b/test/files/run/code.check new file mode 100644 index 0000000000..4bc36424ee --- /dev/null +++ b/test/files/run/code.check @@ -0,0 +1,18 @@ +testing: ((x: Int) => x.$plus(ys.length)) +result = ((x: Int) => x.+{(x: )Int}(ys.length{Int}){Int}){Int => Int} +testing: (() => { + val e: Element = new Element("someName"); + e +}) +result = (() => { + val e: Element = new Element{Element}{(name: )Element}("someName"{java.lang.String("someName")}){Element}; + e{Element} +}{Element}){() => Element} +testing: (() => truc.elem = 6) +result = (() => truc.elem{Int} = 6{Int(6)}{Unit}){() => Unit} +testing: (() => truc.elem = truc.elem.$plus(6)) +result = (() => truc.elem{Int} = truc.elem.+{(x: )Int}(6{Int(6)}){Int}{Unit}){() => Unit} +testing: (() => new baz.BazElement("someName")) +result = (() => new baz.BazElement{baz.BazElement}{(name: )baz.BazElement}("someName"{java.lang.String("someName")}){baz.BazElement}){() => baz.BazElement} +testing: ((x: Int) => x.$plus(ys.length)) +result = ((x: Int) => x.+{(x: )Int}(ys.length{Int}){Int}){Int => Int} diff --git a/test/files/run/code.scala b/test/files/run/code.scala new file mode 100644 index 0000000000..8881c2eda8 --- /dev/null +++ b/test/files/run/code.scala @@ -0,0 +1,52 @@ +import scala.tools.partest.utils.CodeTest + +case class Element(name: String) + +object Test extends App { + case class InnerElement(name: String) + def foo[T](ys: List[T]) = { + val fun: reflect.Code[Int => Int] = x => x + ys.length + fun + } + CodeTest(foo(List(2)), args) + CodeTest({() => val e = Element("someName"); e}, args) +// CodeTest({() => val e = InnerElement("someName"); e}, args) // (does not work yet) + def titi() = { + var truc = 0 + CodeTest(() => { + truc = 6 + }, args) + } + def tata(): Unit = { + var truc = 0 + CodeTest(() => { + truc = truc + 6 + }, args) + } + titi() + tata() + new baz.A(args) + + def show() { + def foo[T](ys: List[T]) = { + val fun: reflect.Code[Int => Int] = x => x + ys.length + CodeTest(fun, args) + } + foo(List(1, 2, 3)) + } + + show() +} + +package baz { + + case class BazElement(name: String) { } + + class A(args: Array[String]) { + CodeTest(() => new baz.BazElement("someName"), args) + } + +} + + + -- cgit v1.2.3