diff options
author | Martin Odersky <odersky@gmail.com> | 2016-09-13 18:15:21 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-10-02 16:12:28 +0200 |
commit | 748d1d852ce28785f61f511758071c70a6137356 (patch) | |
tree | e6a8f0a4d8b8268792958a232e1fdc9f453259be /tests | |
parent | b5132e87afe1a98467369d2f91ba4483a6a88ea4 (diff) | |
download | dotty-748d1d852ce28785f61f511758071c70a6137356.tar.gz dotty-748d1d852ce28785f61f511758071c70a6137356.tar.bz2 dotty-748d1d852ce28785f61f511758071c70a6137356.zip |
Generalize checkInlineConformant to functions
Pure expressions with function types now are considered
conforming. Necessitated a change in TreeInfo to accept
closures as pure expressions.
Test case in inlineForeach
Diffstat (limited to 'tests')
-rw-r--r-- | tests/run/inlineForeach.scala | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/run/inlineForeach.scala b/tests/run/inlineForeach.scala new file mode 100644 index 000000000..0c6135c6d --- /dev/null +++ b/tests/run/inlineForeach.scala @@ -0,0 +1,44 @@ +object Test { + + class Range(from: Int, end: Int) { + + inline + def foreach(inline op: Int => Unit): Unit = { + var i = from + while (i < end) { + op(i) + i += 1 + } + } + + def filter(p: Int => Boolean): List[Int] = ??? + } + + implicit class intWrapper(private val start: Int) extends AnyVal { + def until(end: Int) = new Range(start, end) + def to(limit: Int) = new Range(start, limit + 1) + }/* + + def matmul(xs: Array[Array[Double]], ys: Array[Array[Double]]): Array[Array[Double]] = { + def nrows = xs.length + def ncols = ys(0).length + def n = ys.length + assert(xs(0).length == n) + val zs = Array.ofDim[Double](nrows, ncols) + for (i <- intWrapper(0) until nrows) + for (j <- 0 until ncols) { + var x = 0.0 + for (k <- 0 until n) + x += xs(i)(k) * ys(k)(j) + zs(i)(j) = x + } + zs + } +*/ + def main(args: Array[String]) = { + /* 1.until(10).foreach(i => println(i)) + 1.until(10).foreach(println(_))*/ + 1.until(10).foreach(println) + for (i <- 1 to 10) println(i) + } +} |