diff --git a/tests/disabled/pos-macros/forwardCompat-3.1/Macro_1_r3.1.scala b/tests/disabled/pos-macros/forwardCompat-3.1/Macro_1_r3.1.scala new file mode 100644 index 000000000000..fb06e93f91c0 --- /dev/null +++ b/tests/disabled/pos-macros/forwardCompat-3.1/Macro_1_r3.1.scala @@ -0,0 +1,20 @@ +import scala.quoted.* + +object Macros: + + inline def power(x: Double, inline n: Int) = ${ powerCode('x, 'n) } + + private def powerCode(x: Expr[Double], n: Expr[Int])(using Quotes): Expr[Double] = + unrolledPowerCode(x, n.valueOrError) + + private def unrolledPowerCode(x: Expr[Double], n: Int)(using Quotes): Expr[Double] = + if n == 0 then '{ 1.0 } // tests simple quotes without splices + else if n % 2 == 1 then '{ $x * ${ unrolledPowerCode(x, n - 1) } } // tests simple splices + else '{ val y = $x * $x; ${ unrolledPowerCode('y, n / 2) } } // tests splice with term capture + + + inline def let[T, U](x: T)(inline body: T => U): U = ${ letCode('x, 'body) } + + private def letCode[T: Type, U: Type](x: Expr[T], body: Expr[T => U])(using Quotes): Expr[U] = + // tests use of Type + '{ val y: T = $x; $body(y): U } diff --git a/tests/disabled/pos-macros/forwardCompat-3.1/Test_2_c3.1.0.scala b/tests/disabled/pos-macros/forwardCompat-3.1/Test_2_c3.1.0.scala new file mode 100644 index 000000000000..8c0a8004b9cf --- /dev/null +++ b/tests/disabled/pos-macros/forwardCompat-3.1/Test_2_c3.1.0.scala @@ -0,0 +1,15 @@ +import Macros.* + +def powerTest(x: Double): Unit = + power(x, 0) + power(x, 1) + power(x, 5) + power(x, 10) + +def letTest: Unit = + let(0) { _ + 1 } + let(0) { _.toString } + let((4, 'a')) { _.swap } + let(new Foo) { _.hashCode } + +class Foo diff --git a/tests/disabled/pos-macros/forwardCompat-3.1/why.md b/tests/disabled/pos-macros/forwardCompat-3.1/why.md new file mode 100644 index 000000000000..f281f9c08662 --- /dev/null +++ b/tests/disabled/pos-macros/forwardCompat-3.1/why.md @@ -0,0 +1 @@ +Disabled until https://github.com/lampepfl/dotty/issues/14306 is fixed diff --git a/tests/pos-macros/backwardCompat-3.0/Macro_1_c3.0.0.scala b/tests/pos-macros/backwardCompat-3.0/Macro_1_c3.0.0.scala new file mode 100644 index 000000000000..fb06e93f91c0 --- /dev/null +++ b/tests/pos-macros/backwardCompat-3.0/Macro_1_c3.0.0.scala @@ -0,0 +1,20 @@ +import scala.quoted.* + +object Macros: + + inline def power(x: Double, inline n: Int) = ${ powerCode('x, 'n) } + + private def powerCode(x: Expr[Double], n: Expr[Int])(using Quotes): Expr[Double] = + unrolledPowerCode(x, n.valueOrError) + + private def unrolledPowerCode(x: Expr[Double], n: Int)(using Quotes): Expr[Double] = + if n == 0 then '{ 1.0 } // tests simple quotes without splices + else if n % 2 == 1 then '{ $x * ${ unrolledPowerCode(x, n - 1) } } // tests simple splices + else '{ val y = $x * $x; ${ unrolledPowerCode('y, n / 2) } } // tests splice with term capture + + + inline def let[T, U](x: T)(inline body: T => U): U = ${ letCode('x, 'body) } + + private def letCode[T: Type, U: Type](x: Expr[T], body: Expr[T => U])(using Quotes): Expr[U] = + // tests use of Type + '{ val y: T = $x; $body(y): U } diff --git a/tests/pos-macros/backwardCompat-3.0/Test_2.scala b/tests/pos-macros/backwardCompat-3.0/Test_2.scala new file mode 100644 index 000000000000..8c0a8004b9cf --- /dev/null +++ b/tests/pos-macros/backwardCompat-3.0/Test_2.scala @@ -0,0 +1,15 @@ +import Macros.* + +def powerTest(x: Double): Unit = + power(x, 0) + power(x, 1) + power(x, 5) + power(x, 10) + +def letTest: Unit = + let(0) { _ + 1 } + let(0) { _.toString } + let((4, 'a')) { _.swap } + let(new Foo) { _.hashCode } + +class Foo diff --git a/tests/pos-macros/backwardCompat-3.1/Macro_1_c3.1.0.scala b/tests/pos-macros/backwardCompat-3.1/Macro_1_c3.1.0.scala new file mode 100644 index 000000000000..fb06e93f91c0 --- /dev/null +++ b/tests/pos-macros/backwardCompat-3.1/Macro_1_c3.1.0.scala @@ -0,0 +1,20 @@ +import scala.quoted.* + +object Macros: + + inline def power(x: Double, inline n: Int) = ${ powerCode('x, 'n) } + + private def powerCode(x: Expr[Double], n: Expr[Int])(using Quotes): Expr[Double] = + unrolledPowerCode(x, n.valueOrError) + + private def unrolledPowerCode(x: Expr[Double], n: Int)(using Quotes): Expr[Double] = + if n == 0 then '{ 1.0 } // tests simple quotes without splices + else if n % 2 == 1 then '{ $x * ${ unrolledPowerCode(x, n - 1) } } // tests simple splices + else '{ val y = $x * $x; ${ unrolledPowerCode('y, n / 2) } } // tests splice with term capture + + + inline def let[T, U](x: T)(inline body: T => U): U = ${ letCode('x, 'body) } + + private def letCode[T: Type, U: Type](x: Expr[T], body: Expr[T => U])(using Quotes): Expr[U] = + // tests use of Type + '{ val y: T = $x; $body(y): U } diff --git a/tests/pos-macros/backwardCompat-3.1/Test_2.scala b/tests/pos-macros/backwardCompat-3.1/Test_2.scala new file mode 100644 index 000000000000..8c0a8004b9cf --- /dev/null +++ b/tests/pos-macros/backwardCompat-3.1/Test_2.scala @@ -0,0 +1,15 @@ +import Macros.* + +def powerTest(x: Double): Unit = + power(x, 0) + power(x, 1) + power(x, 5) + power(x, 10) + +def letTest: Unit = + let(0) { _ + 1 } + let(0) { _.toString } + let((4, 'a')) { _.swap } + let(new Foo) { _.hashCode } + +class Foo diff --git a/tests/pos-macros/baseCompat/Macro_1.scala b/tests/pos-macros/baseCompat/Macro_1.scala new file mode 100644 index 000000000000..fb06e93f91c0 --- /dev/null +++ b/tests/pos-macros/baseCompat/Macro_1.scala @@ -0,0 +1,20 @@ +import scala.quoted.* + +object Macros: + + inline def power(x: Double, inline n: Int) = ${ powerCode('x, 'n) } + + private def powerCode(x: Expr[Double], n: Expr[Int])(using Quotes): Expr[Double] = + unrolledPowerCode(x, n.valueOrError) + + private def unrolledPowerCode(x: Expr[Double], n: Int)(using Quotes): Expr[Double] = + if n == 0 then '{ 1.0 } // tests simple quotes without splices + else if n % 2 == 1 then '{ $x * ${ unrolledPowerCode(x, n - 1) } } // tests simple splices + else '{ val y = $x * $x; ${ unrolledPowerCode('y, n / 2) } } // tests splice with term capture + + + inline def let[T, U](x: T)(inline body: T => U): U = ${ letCode('x, 'body) } + + private def letCode[T: Type, U: Type](x: Expr[T], body: Expr[T => U])(using Quotes): Expr[U] = + // tests use of Type + '{ val y: T = $x; $body(y): U } diff --git a/tests/pos-macros/baseCompat/Test_2.scala b/tests/pos-macros/baseCompat/Test_2.scala new file mode 100644 index 000000000000..8c0a8004b9cf --- /dev/null +++ b/tests/pos-macros/baseCompat/Test_2.scala @@ -0,0 +1,15 @@ +import Macros.* + +def powerTest(x: Double): Unit = + power(x, 0) + power(x, 1) + power(x, 5) + power(x, 10) + +def letTest: Unit = + let(0) { _ + 1 } + let(0) { _.toString } + let((4, 'a')) { _.swap } + let(new Foo) { _.hashCode } + +class Foo diff --git a/tests/pos-macros/forwardCompat-3.0/Macro_1_r3.0.scala b/tests/pos-macros/forwardCompat-3.0/Macro_1_r3.0.scala new file mode 100644 index 000000000000..fb06e93f91c0 --- /dev/null +++ b/tests/pos-macros/forwardCompat-3.0/Macro_1_r3.0.scala @@ -0,0 +1,20 @@ +import scala.quoted.* + +object Macros: + + inline def power(x: Double, inline n: Int) = ${ powerCode('x, 'n) } + + private def powerCode(x: Expr[Double], n: Expr[Int])(using Quotes): Expr[Double] = + unrolledPowerCode(x, n.valueOrError) + + private def unrolledPowerCode(x: Expr[Double], n: Int)(using Quotes): Expr[Double] = + if n == 0 then '{ 1.0 } // tests simple quotes without splices + else if n % 2 == 1 then '{ $x * ${ unrolledPowerCode(x, n - 1) } } // tests simple splices + else '{ val y = $x * $x; ${ unrolledPowerCode('y, n / 2) } } // tests splice with term capture + + + inline def let[T, U](x: T)(inline body: T => U): U = ${ letCode('x, 'body) } + + private def letCode[T: Type, U: Type](x: Expr[T], body: Expr[T => U])(using Quotes): Expr[U] = + // tests use of Type + '{ val y: T = $x; $body(y): U } diff --git a/tests/pos-macros/forwardCompat-3.0/Test_2_c3.0.0.scala b/tests/pos-macros/forwardCompat-3.0/Test_2_c3.0.0.scala new file mode 100644 index 000000000000..8c0a8004b9cf --- /dev/null +++ b/tests/pos-macros/forwardCompat-3.0/Test_2_c3.0.0.scala @@ -0,0 +1,15 @@ +import Macros.* + +def powerTest(x: Double): Unit = + power(x, 0) + power(x, 1) + power(x, 5) + power(x, 10) + +def letTest: Unit = + let(0) { _ + 1 } + let(0) { _.toString } + let((4, 'a')) { _.swap } + let(new Foo) { _.hashCode } + +class Foo