diff options
author | odersky <odersky@gmail.com> | 2015-06-18 10:58:07 +0200 |
---|---|---|
committer | odersky <odersky@gmail.com> | 2015-06-18 10:58:07 +0200 |
commit | 2ce159fa1707c1e57e22af9b2fe5a87fee94ee8d (patch) | |
tree | c13a7f302e0b949dac99249e66962230df43064a /tests/disabled/macro/run/macro-range/Expansion_Impossible_2.scala | |
parent | 78fae1152a7b381af4639d3d66ed637eac3ca9d0 (diff) | |
parent | 797bfd74b0900d18d62082b842f6a330ce414ebd (diff) | |
download | dotty-2ce159fa1707c1e57e22af9b2fe5a87fee94ee8d.tar.gz dotty-2ce159fa1707c1e57e22af9b2fe5a87fee94ee8d.tar.bz2 dotty-2ce159fa1707c1e57e22af9b2fe5a87fee94ee8d.zip |
Merge pull request #664 from dotty-staging/more-tests
Enable tests that pass, move macro tests to disabled.
Diffstat (limited to 'tests/disabled/macro/run/macro-range/Expansion_Impossible_2.scala')
-rw-r--r-- | tests/disabled/macro/run/macro-range/Expansion_Impossible_2.scala | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/disabled/macro/run/macro-range/Expansion_Impossible_2.scala b/tests/disabled/macro/run/macro-range/Expansion_Impossible_2.scala new file mode 100644 index 000000000..b3c2fa348 --- /dev/null +++ b/tests/disabled/macro/run/macro-range/Expansion_Impossible_2.scala @@ -0,0 +1,53 @@ +import scala.reflect.macros.blackbox.Context + +object Impls { + def foreach(c: Context)(f: c.Expr[Int => Unit]): c.Expr[Unit] = { + // todo. read the compiler config and print if -Ydebug is set + //println("macro-expand, _this = "+ _this) + object utils extends Utils { val context: c.type = c } + import utils._ + import c.universe._ + import Flag._ + + val initName = termNames.CONSTRUCTOR + // Either: + // scala"{ var i = $low; val h = $hi; while (i < h) { $f(i); i = i + 1 } } + // or: + // scala"($_this: RangeDefault).foreach($f)" + c.Expr(c.prefix.tree match { + case Apply(Select(New(tpt), initName), List(lo, hi)) if tpt.symbol.fullName == "Range" => + val iname = TermName("$i") + val hname = TermName("$h") + def iref = Ident(iname) + def href = Ident(hname) + val labelname = TermName("$while") + val cond = makeBinop(iref, "$less", href) + val body = Block( + List(makeApply(f.tree, List(iref))), + Assign(iref, makeBinop(iref, "$plus", Literal(Constant(1))))) + val generated = + Block( + List( + ValDef(Modifiers(MUTABLE), iname, TypeTree(), lo), + ValDef(Modifiers(), hname, TypeTree(), hi)), + makeWhile(labelname, cond, body)) + // todo. read the compiler config and print if -Ydebug is set + //tools.nsc.util.trace("generated: ")(generated) + generated + case _ => + Apply( + Select( + Typed(c.prefix.tree, Ident(TypeName("RangeDefault"))), + TermName("foreach")), + List(f.tree)) + }) + } +} + +class Range(val from: Int, val to: Int) extends RangeDefault { + override def foreach(f: Int => Unit): Unit = macro Impls.foreach +} + +object Test extends dotty.runtime.LegacyApp { + new Range(1, 10) foreach println +}
\ No newline at end of file |