Skip to content

Commit 4c1512b

Browse files
committed
Upgrade Scala 3 version to 3.0.0-M2
1 parent 8a4f750 commit 4c1512b

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/main/g8/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
val dottyVersion = "3.0.0-M1"
1+
val dottyVersion = "3.0.0-M2"
22

33
lazy val root = project
44
.in(file("."))

src/main/g8/src/main/scala/Main.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
// Import Expr and some extension methods
33
import scala.quoted._
4-
import scala.quoted.staging.{run, withQuoteContext, Toolbox}
4+
import scala.quoted.staging.{run, withQuotes, Toolbox}
55

66
object Main {
77

@@ -24,21 +24,21 @@ object Main {
2424

2525
def stagedPower(n: Int): Double => Double = {
2626
// Code representing the labmda where the recursion is unrolled based on the value of n
27-
def code(using QuoteContext) = '{ (x: Double) => \${ powerCode(n, 'x) } }
27+
def code(using Quotes) = '{ (x: Double) => \${ powerCode(n, 'x) } }
2828

2929
println(s"staged power for n=" + n + ":")
30-
println(withQuoteContext(code.show))
30+
println(withQuotes(code.show))
3131

3232
// Evaluate the contents of the code and return it's value
3333
run(code)
3434
}
3535

36-
def powerCode(n: Int, x: Expr[Double])(using ctx: QuoteContext): Expr[Double] =
37-
if (n == 0) Expr(1.0) // Expr() lifts 1.0 to '{1.0}
38-
else if (n == 1) x // optimization to not generate x * 1
39-
else if (n < 0) throw new Exception("Negative powers not implemented. Left as a small exercise. Dont be shy, try it out.")
40-
else if (n == 2) '{ \$x * \$x } // optimization to not generate { val y = x; y * y }
41-
else if (n % 2 == 1) '{ \$x * \${ powerCode(n - 1, x) } }
42-
else '{ val y = \$x * \$x; \${ powerCode(n / 2, 'y) } }
36+
def powerCode(n: Int, x: Expr[Double])(using Quotes): Expr[Double] =
37+
if (n == 0) Expr(1.0) // Expr() lifts 1.0 to '{1.0}
38+
else if (n == 1) x // optimization to not generate x * 1
39+
else if (n < 0) throw new Exception("Negative powers not implemented. Left as a small exercise. Dont be shy, try it out.")
40+
else if (n == 2) '{ \$x * \$x } // optimization to not generate { val y = x; y * y }
41+
else if (n % 2 == 1) '{ \$x * \${ powerCode(n - 1, x) } }
42+
else '{ val y = \$x * \$x; \${ powerCode(n / 2, 'y) } }
4343

4444
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
import scala.quoted._
3-
import scala.quoted.staging.{run, withQuoteContext, Toolbox}
3+
import scala.quoted.staging.{run, withQuotes, Toolbox}
44

55
import org.junit.Test
66
import org.junit.Assert._
@@ -10,10 +10,10 @@ class Test1 {
1010
// Needed to run or show quotes
1111
given Toolbox = Toolbox.make(getClass.getClassLoader)
1212

13-
private def code(using QuoteContext) = '{ identity("foo") }
13+
private def code(using Quotes) = '{ identity("foo") }
1414

1515
@Test def t1(): Unit = {
16-
assertEquals("scala.Predef.identity[java.lang.String](\"foo\")", withQuoteContext(code.show))
16+
assertEquals("scala.Predef.identity[java.lang.String](\"foo\")", withQuotes(code.show))
1717
assertEquals("foo", run(code))
1818
}
1919
}

0 commit comments

Comments
 (0)