From 09ef8730d13eff1cf200bbfb0f6fda7f6d72524a Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Fri, 14 Dec 2012 17:09:55 +0400 Subject: SI-6591 Reify and path-dependent types Reification scheme changed. Now Select an SelectFromTypeTree trees reified appropriately, as Select and SelectFromTypeTree accordingly. Packages and Predef object was excluded in order not to break the existing reification scheme and not to break tests which rely on it. Reified free terms can contain flag to make reified values become stable identifiers. For example in the case of reify_newimpl_15.scala class C { type T reify { val v: List[T] = List(2) } } class C reified as free term C$value, and List[C.T] becomes List[C$value().T], so C$value.apply() need to pass stability test isExprSafeToInline at scala.reflect.internal.TreeInfo. For this purpose special case for reified free terms was added to isExprSafeToInline function. test run/reify_newipl_30 disabled due to SI-7082 test t6591_4 moved to pending due to SI-7083 --- test/files/run/reify_newimpl_30.check | 3 ++- test/files/run/reify_newimpl_30.scala | 7 ++++--- test/files/run/t6591_1.check | 1 + test/files/run/t6591_1.scala | 19 +++++++++++++++++++ test/files/run/t6591_2.check | 1 + test/files/run/t6591_2.scala | 19 +++++++++++++++++++ test/files/run/t6591_3.check | 1 + test/files/run/t6591_3.scala | 17 +++++++++++++++++ test/files/run/t6591_5.check | 1 + test/files/run/t6591_5.scala | 23 +++++++++++++++++++++++ test/files/run/t6591_6.check | 1 + test/files/run/t6591_6.scala | 24 ++++++++++++++++++++++++ 12 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 test/files/run/t6591_1.check create mode 100644 test/files/run/t6591_1.scala create mode 100644 test/files/run/t6591_2.check create mode 100644 test/files/run/t6591_2.scala create mode 100644 test/files/run/t6591_3.check create mode 100644 test/files/run/t6591_3.scala create mode 100644 test/files/run/t6591_5.check create mode 100644 test/files/run/t6591_5.scala create mode 100644 test/files/run/t6591_6.check create mode 100644 test/files/run/t6591_6.scala (limited to 'test/files/run') diff --git a/test/files/run/reify_newimpl_30.check b/test/files/run/reify_newimpl_30.check index c23af69b08..29baac911e 100644 --- a/test/files/run/reify_newimpl_30.check +++ b/test/files/run/reify_newimpl_30.check @@ -1 +1,2 @@ -List(2) +reflective toolbox has failed: +unresolved free type variables (namely: C defined by in reify_newimpl_30.scala:7:11). have you forgot to use TypeTag annotations for type parameters external to a reifee? if you have troubles tracking free type variables, consider using -Xlog-free-types diff --git a/test/files/run/reify_newimpl_30.scala b/test/files/run/reify_newimpl_30.scala index 573d05a630..bc34f1bb6c 100644 --- a/test/files/run/reify_newimpl_30.scala +++ b/test/files/run/reify_newimpl_30.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.tools.reflect.ToolBox +import scala.tools.reflect.{ ToolBox, ToolBoxError } import scala.tools.reflect.Eval object Test extends App { @@ -9,9 +9,10 @@ object Test extends App { val code = reify { List[C#T](2) } - println(code.eval) + try { println(code.eval) } + catch { case e: ToolBoxError => println(e.getMessage) } } new C } -} \ No newline at end of file +} diff --git a/test/files/run/t6591_1.check b/test/files/run/t6591_1.check new file mode 100644 index 0000000000..b6cb6c286d --- /dev/null +++ b/test/files/run/t6591_1.check @@ -0,0 +1 @@ +Block(List(ValDef(Modifiers(), newTermName("v"), Select(Ident(A), newTypeName("I")), Select(Ident(A), newTermName("impl")))), Ident(newTermName("v"))) diff --git a/test/files/run/t6591_1.scala b/test/files/run/t6591_1.scala new file mode 100644 index 0000000000..6dd9a1d9fb --- /dev/null +++ b/test/files/run/t6591_1.scala @@ -0,0 +1,19 @@ +import scala.reflect.runtime.universe._ +import scala.tools.reflect.ToolBox +import scala.tools.reflect.Eval + +trait O { trait I } + +object A extends O { + val impl = new I {} +} + +object Test extends App { + val code = reify { + val v: A.I = A.impl + v + } + println(showRaw(code.tree)) + + val v: A.I = code.eval +} diff --git a/test/files/run/t6591_2.check b/test/files/run/t6591_2.check new file mode 100644 index 0000000000..b2d5797cbf --- /dev/null +++ b/test/files/run/t6591_2.check @@ -0,0 +1 @@ +Block(List(ValDef(Modifiers(), newTermName("v"), SelectFromTypeTree(Ident(A), newTypeName("I")), Select(Apply(Select(New(Ident(A)), nme.CONSTRUCTOR), List()), newTermName("impl")))), Ident(newTermName("v"))) diff --git a/test/files/run/t6591_2.scala b/test/files/run/t6591_2.scala new file mode 100644 index 0000000000..6214308dab --- /dev/null +++ b/test/files/run/t6591_2.scala @@ -0,0 +1,19 @@ +import scala.reflect.runtime.universe._ +import scala.tools.reflect.ToolBox +import scala.tools.reflect.Eval + +trait O { trait I } + +class A extends O { + val impl = new I {} +} + +object Test extends App { + val code = reify { + val v: A#I = (new A).impl + v + } + println(showRaw(code.tree)) + + val v: A#I = code.eval +} diff --git a/test/files/run/t6591_3.check b/test/files/run/t6591_3.check new file mode 100644 index 0000000000..a7b594ba65 --- /dev/null +++ b/test/files/run/t6591_3.check @@ -0,0 +1 @@ +Block(List(ValDef(Modifiers(), newTermName("v"), Select(This(newTypeName("A")), newTypeName("I")), Apply(Select(New(Select(This(newTypeName("A")), newTypeName("I"))), nme.CONSTRUCTOR), List()))), Ident(newTermName("v"))) diff --git a/test/files/run/t6591_3.scala b/test/files/run/t6591_3.scala new file mode 100644 index 0000000000..b73a7baf48 --- /dev/null +++ b/test/files/run/t6591_3.scala @@ -0,0 +1,17 @@ +import scala.reflect.runtime.universe._ +import scala.tools.reflect.ToolBox +import scala.tools.reflect.Eval + +class O { class I } + +object A extends O { + val code = reify { + val v: I = new I + v + } + println(showRaw(code.tree)) +} + +object Test extends App { + val v: A.I = A.code.eval +} diff --git a/test/files/run/t6591_5.check b/test/files/run/t6591_5.check new file mode 100644 index 0000000000..8f1c2b3ede --- /dev/null +++ b/test/files/run/t6591_5.check @@ -0,0 +1 @@ +Expr(Block(List(ValDef(Modifiers(), newTermName("v"), Select(Select(This(newTypeName("A")), newTermName("x")), newTypeName("I")), Select(Select(This(newTypeName("scala")), newTermName("Predef")), newTermName("$qmark$qmark$qmark")))), Ident(newTermName("v")))) diff --git a/test/files/run/t6591_5.scala b/test/files/run/t6591_5.scala new file mode 100644 index 0000000000..18d6f90a9b --- /dev/null +++ b/test/files/run/t6591_5.scala @@ -0,0 +1,23 @@ +import scala.reflect.runtime.universe._ +import scala.tools.reflect.ToolBox +import scala.tools.reflect.Eval +import java.lang.reflect.InvocationTargetException + +class O { class I } + +object A extends O { + val x = new O + val code = reify { + val v: x.I = ??? + v + } + println(showRaw(code)) +} + +object Test extends App { + try { + val v: A.x.I = A.code.eval + } catch { + case ex: InvocationTargetException if ex.getCause.isInstanceOf[NotImplementedError] => + } +} diff --git a/test/files/run/t6591_6.check b/test/files/run/t6591_6.check new file mode 100644 index 0000000000..5ddf7600f1 --- /dev/null +++ b/test/files/run/t6591_6.check @@ -0,0 +1 @@ +Expr(Block(List(ValDef(Modifiers(), newTermName("v"), Select(Select(Ident(newTermName("A")), newTermName("x")), newTypeName("I")), Select(Select(This(newTypeName("scala")), newTermName("Predef")), newTermName("$qmark$qmark$qmark")))), Ident(newTermName("v")))) diff --git a/test/files/run/t6591_6.scala b/test/files/run/t6591_6.scala new file mode 100644 index 0000000000..2eee87928d --- /dev/null +++ b/test/files/run/t6591_6.scala @@ -0,0 +1,24 @@ +import scala.language.existentials +import scala.reflect.runtime.universe._ +import scala.tools.reflect.ToolBox +import scala.tools.reflect.Eval +import java.lang.reflect.InvocationTargetException + +class O { class I } + +class A extends O { + val x = new O + val code = reify { + val v: x.I = ??? + v + } + println(showRaw(code)) +} + +object Test extends App { + try { + val v = (new A).code.eval + } catch { + case ex: InvocationTargetException if ex.getCause.isInstanceOf[NotImplementedError] => + } +} -- cgit v1.2.3