From dfbaaa179fddd3d37abf66a08080f646b8557b6f Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Sun, 27 Jan 2013 13:31:06 +0100 Subject: SI-6187 Make partial functions re-typable - `New(tpe)` doesn't survive a `resetAttrs` / typecheck; use a name instead. - Abandon the tree attachment that passed the default case from `typer` to `patmat`; this tree eluded the attribute reset performed in the macro. Instead, add it to the match. Apart from making the tree re-typable, it also exposes the true code structure to macros, which is important if they need to perform other code transformations. - Install original trees on the declared types of the parameters of the `applyOrElse` method to ensure that references to them within the method pick up the correct type parameter skolems upon retypechecking. - Propagate `TypeTree#original` through `copyAttrs`, which is called during tree duplication / `TreeCopiers`. Without this, the original trees that we installed were not visible anymore during `ResetAttrs`. We are not able to reify partial functions yet -- the particular sticking point is reification of the parentage which is only available in the `ClassInfoType`. --- .../run/idempotency-partial-functions.scala | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test/pending/run/idempotency-partial-functions.scala (limited to 'test/pending/run') diff --git a/test/pending/run/idempotency-partial-functions.scala b/test/pending/run/idempotency-partial-functions.scala new file mode 100644 index 0000000000..bc0ca706dd --- /dev/null +++ b/test/pending/run/idempotency-partial-functions.scala @@ -0,0 +1,28 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{currentMirror => cm} +import scala.tools.reflect.{ToolBox, ToolBoxError} +import scala.tools.reflect.Eval + +// Related to SI-6187 +// +// Moved to pending as we are currently blocked by the inability +// to reify the parent types of the anoymous function class, +// which are not part of the tree, but rather only part of the +// ClassInfoType. +object Test extends App { + val partials = reify { + List((false,true)) collect { case (x,true) => x } + } + println(Seq(show(partials), showRaw(partials)).mkString("\n\n")) + try { + println(partials.eval) + } catch { + case e: ToolBoxError => println(e) + } + val tb = cm.mkToolBox() + val tpartials = tb.typeCheck(partials.tree) + println(tpartials) + val rtpartials = tb.resetAllAttrs(tpartials) + println(tb.eval(rtpartials)) +} +Test.main(null) \ No newline at end of file -- cgit v1.2.3