From d4d077da617c689debb3b1f9f3eadc0691175d10 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 20 Jan 2022 11:18:46 +0100 Subject: [PATCH 1/6] Add forward compat tests for macros --- .../forwardCompat-3.0/Macro_1_c3.0.0.scala | 20 +++++++++++++++++++ .../pos-macros/forwardCompat-3.0/Test_2.scala | 15 ++++++++++++++ .../forwardCompat-3.1/Macro_1_c3.1.0.scala | 20 +++++++++++++++++++ .../pos-macros/forwardCompat-3.1/Test_2.scala | 15 ++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 tests/pos-macros/forwardCompat-3.0/Macro_1_c3.0.0.scala create mode 100644 tests/pos-macros/forwardCompat-3.0/Test_2.scala create mode 100644 tests/pos-macros/forwardCompat-3.1/Macro_1_c3.1.0.scala create mode 100644 tests/pos-macros/forwardCompat-3.1/Test_2.scala diff --git a/tests/pos-macros/forwardCompat-3.0/Macro_1_c3.0.0.scala b/tests/pos-macros/forwardCompat-3.0/Macro_1_c3.0.0.scala new file mode 100644 index 000000000000..fb06e93f91c0 --- /dev/null +++ b/tests/pos-macros/forwardCompat-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/forwardCompat-3.0/Test_2.scala b/tests/pos-macros/forwardCompat-3.0/Test_2.scala new file mode 100644 index 000000000000..8c0a8004b9cf --- /dev/null +++ b/tests/pos-macros/forwardCompat-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/forwardCompat-3.1/Macro_1_c3.1.0.scala b/tests/pos-macros/forwardCompat-3.1/Macro_1_c3.1.0.scala new file mode 100644 index 000000000000..fb06e93f91c0 --- /dev/null +++ b/tests/pos-macros/forwardCompat-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/forwardCompat-3.1/Test_2.scala b/tests/pos-macros/forwardCompat-3.1/Test_2.scala new file mode 100644 index 000000000000..8c0a8004b9cf --- /dev/null +++ b/tests/pos-macros/forwardCompat-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 From fcda72576a9a87553f4777f784b57cc383160c9e Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 20 Jan 2022 11:59:21 +0100 Subject: [PATCH 2/6] Add backwards compat tests for macros --- .../backwardCompat-3.0/Macro_1_r3.0.scala | 20 +++++++++++++++++++ .../backwardCompat-3.0/Test_2_c3.0.0.scala | 15 ++++++++++++++ .../backwardCompat-3.1/Macro_1_r3.1.scala | 20 +++++++++++++++++++ .../backwardCompat-3.1/Test_2_c3.1.0.scala | 15 ++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 tests/pos-macros/backwardCompat-3.0/Macro_1_r3.0.scala create mode 100644 tests/pos-macros/backwardCompat-3.0/Test_2_c3.0.0.scala create mode 100644 tests/pos-macros/backwardCompat-3.1/Macro_1_r3.1.scala create mode 100644 tests/pos-macros/backwardCompat-3.1/Test_2_c3.1.0.scala diff --git a/tests/pos-macros/backwardCompat-3.0/Macro_1_r3.0.scala b/tests/pos-macros/backwardCompat-3.0/Macro_1_r3.0.scala new file mode 100644 index 000000000000..fb06e93f91c0 --- /dev/null +++ b/tests/pos-macros/backwardCompat-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/backwardCompat-3.0/Test_2_c3.0.0.scala b/tests/pos-macros/backwardCompat-3.0/Test_2_c3.0.0.scala new file mode 100644 index 000000000000..8c0a8004b9cf --- /dev/null +++ b/tests/pos-macros/backwardCompat-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 diff --git a/tests/pos-macros/backwardCompat-3.1/Macro_1_r3.1.scala b/tests/pos-macros/backwardCompat-3.1/Macro_1_r3.1.scala new file mode 100644 index 000000000000..fb06e93f91c0 --- /dev/null +++ b/tests/pos-macros/backwardCompat-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/pos-macros/backwardCompat-3.1/Test_2_c3.1.0.scala b/tests/pos-macros/backwardCompat-3.1/Test_2_c3.1.0.scala new file mode 100644 index 000000000000..8c0a8004b9cf --- /dev/null +++ b/tests/pos-macros/backwardCompat-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 From c3eaadd2daeb797b49097d397ab977dede7025f2 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 20 Jan 2022 13:06:28 +0100 Subject: [PATCH 3/6] Add version of compat test that compiles on current version --- tests/pos-macros/baseCompat/Macro_1.scala | 20 ++++++++++++++++++++ tests/pos-macros/baseCompat/Test_2.scala | 15 +++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 tests/pos-macros/baseCompat/Macro_1.scala create mode 100644 tests/pos-macros/baseCompat/Test_2.scala 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 From 1043f8975d559979cf60fe60ec650ee60fbe41f7 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 20 Jan 2022 14:10:52 +0100 Subject: [PATCH 4/6] Disable tests/pos-macros/backwardCompat-3.1 Because of #14306 --- .../pos-macros/backwardCompat-3.1/Macro_1_r3.1.scala | 0 .../pos-macros/backwardCompat-3.1/Test_2_c3.1.0.scala | 0 tests/disabled/pos-macros/backwardCompat-3.1/why.md | 1 + tests/pos/mytest/A_1_r3.1.scala | 1 + tests/pos/mytest/B_2_c3.1.0.scala | 1 + 5 files changed, 3 insertions(+) rename tests/{ => disabled}/pos-macros/backwardCompat-3.1/Macro_1_r3.1.scala (100%) rename tests/{ => disabled}/pos-macros/backwardCompat-3.1/Test_2_c3.1.0.scala (100%) create mode 100644 tests/disabled/pos-macros/backwardCompat-3.1/why.md create mode 100644 tests/pos/mytest/A_1_r3.1.scala create mode 100644 tests/pos/mytest/B_2_c3.1.0.scala diff --git a/tests/pos-macros/backwardCompat-3.1/Macro_1_r3.1.scala b/tests/disabled/pos-macros/backwardCompat-3.1/Macro_1_r3.1.scala similarity index 100% rename from tests/pos-macros/backwardCompat-3.1/Macro_1_r3.1.scala rename to tests/disabled/pos-macros/backwardCompat-3.1/Macro_1_r3.1.scala diff --git a/tests/pos-macros/backwardCompat-3.1/Test_2_c3.1.0.scala b/tests/disabled/pos-macros/backwardCompat-3.1/Test_2_c3.1.0.scala similarity index 100% rename from tests/pos-macros/backwardCompat-3.1/Test_2_c3.1.0.scala rename to tests/disabled/pos-macros/backwardCompat-3.1/Test_2_c3.1.0.scala diff --git a/tests/disabled/pos-macros/backwardCompat-3.1/why.md b/tests/disabled/pos-macros/backwardCompat-3.1/why.md new file mode 100644 index 000000000000..f281f9c08662 --- /dev/null +++ b/tests/disabled/pos-macros/backwardCompat-3.1/why.md @@ -0,0 +1 @@ +Disabled until https://github.com/lampepfl/dotty/issues/14306 is fixed diff --git a/tests/pos/mytest/A_1_r3.1.scala b/tests/pos/mytest/A_1_r3.1.scala new file mode 100644 index 000000000000..c389887ee5aa --- /dev/null +++ b/tests/pos/mytest/A_1_r3.1.scala @@ -0,0 +1 @@ +class Foo diff --git a/tests/pos/mytest/B_2_c3.1.0.scala b/tests/pos/mytest/B_2_c3.1.0.scala new file mode 100644 index 000000000000..458d393cfa09 --- /dev/null +++ b/tests/pos/mytest/B_2_c3.1.0.scala @@ -0,0 +1 @@ +class Bar extends Foo From 4c2fead90c2004a38ba2433b86519591b91288ea Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 21 Jan 2022 08:36:11 +0100 Subject: [PATCH 5/6] Remove #14306 test --- tests/pos/mytest/A_1_r3.1.scala | 1 - tests/pos/mytest/B_2_c3.1.0.scala | 1 - 2 files changed, 2 deletions(-) delete mode 100644 tests/pos/mytest/A_1_r3.1.scala delete mode 100644 tests/pos/mytest/B_2_c3.1.0.scala diff --git a/tests/pos/mytest/A_1_r3.1.scala b/tests/pos/mytest/A_1_r3.1.scala deleted file mode 100644 index c389887ee5aa..000000000000 --- a/tests/pos/mytest/A_1_r3.1.scala +++ /dev/null @@ -1 +0,0 @@ -class Foo diff --git a/tests/pos/mytest/B_2_c3.1.0.scala b/tests/pos/mytest/B_2_c3.1.0.scala deleted file mode 100644 index 458d393cfa09..000000000000 --- a/tests/pos/mytest/B_2_c3.1.0.scala +++ /dev/null @@ -1 +0,0 @@ -class Bar extends Foo From 98be6b9444a085c7174718bc5704539679585f57 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 26 Jan 2022 11:48:17 +0100 Subject: [PATCH 6/6] Reverse test naming backward/forward --- .../{backwardCompat-3.1 => forwardCompat-3.1}/Macro_1_r3.1.scala | 0 .../{backwardCompat-3.1 => forwardCompat-3.1}/Test_2_c3.1.0.scala | 0 .../pos-macros/{backwardCompat-3.1 => forwardCompat-3.1}/why.md | 0 .../Macro_1_c3.0.0.scala | 0 .../{forwardCompat-3.0 => backwardCompat-3.0}/Test_2.scala | 0 .../Macro_1_c3.1.0.scala | 0 .../{forwardCompat-3.1 => backwardCompat-3.1}/Test_2.scala | 0 .../{backwardCompat-3.0 => forwardCompat-3.0}/Macro_1_r3.0.scala | 0 .../{backwardCompat-3.0 => forwardCompat-3.0}/Test_2_c3.0.0.scala | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename tests/disabled/pos-macros/{backwardCompat-3.1 => forwardCompat-3.1}/Macro_1_r3.1.scala (100%) rename tests/disabled/pos-macros/{backwardCompat-3.1 => forwardCompat-3.1}/Test_2_c3.1.0.scala (100%) rename tests/disabled/pos-macros/{backwardCompat-3.1 => forwardCompat-3.1}/why.md (100%) rename tests/pos-macros/{forwardCompat-3.0 => backwardCompat-3.0}/Macro_1_c3.0.0.scala (100%) rename tests/pos-macros/{forwardCompat-3.0 => backwardCompat-3.0}/Test_2.scala (100%) rename tests/pos-macros/{forwardCompat-3.1 => backwardCompat-3.1}/Macro_1_c3.1.0.scala (100%) rename tests/pos-macros/{forwardCompat-3.1 => backwardCompat-3.1}/Test_2.scala (100%) rename tests/pos-macros/{backwardCompat-3.0 => forwardCompat-3.0}/Macro_1_r3.0.scala (100%) rename tests/pos-macros/{backwardCompat-3.0 => forwardCompat-3.0}/Test_2_c3.0.0.scala (100%) diff --git a/tests/disabled/pos-macros/backwardCompat-3.1/Macro_1_r3.1.scala b/tests/disabled/pos-macros/forwardCompat-3.1/Macro_1_r3.1.scala similarity index 100% rename from tests/disabled/pos-macros/backwardCompat-3.1/Macro_1_r3.1.scala rename to tests/disabled/pos-macros/forwardCompat-3.1/Macro_1_r3.1.scala diff --git a/tests/disabled/pos-macros/backwardCompat-3.1/Test_2_c3.1.0.scala b/tests/disabled/pos-macros/forwardCompat-3.1/Test_2_c3.1.0.scala similarity index 100% rename from tests/disabled/pos-macros/backwardCompat-3.1/Test_2_c3.1.0.scala rename to tests/disabled/pos-macros/forwardCompat-3.1/Test_2_c3.1.0.scala diff --git a/tests/disabled/pos-macros/backwardCompat-3.1/why.md b/tests/disabled/pos-macros/forwardCompat-3.1/why.md similarity index 100% rename from tests/disabled/pos-macros/backwardCompat-3.1/why.md rename to tests/disabled/pos-macros/forwardCompat-3.1/why.md diff --git a/tests/pos-macros/forwardCompat-3.0/Macro_1_c3.0.0.scala b/tests/pos-macros/backwardCompat-3.0/Macro_1_c3.0.0.scala similarity index 100% rename from tests/pos-macros/forwardCompat-3.0/Macro_1_c3.0.0.scala rename to tests/pos-macros/backwardCompat-3.0/Macro_1_c3.0.0.scala diff --git a/tests/pos-macros/forwardCompat-3.0/Test_2.scala b/tests/pos-macros/backwardCompat-3.0/Test_2.scala similarity index 100% rename from tests/pos-macros/forwardCompat-3.0/Test_2.scala rename to tests/pos-macros/backwardCompat-3.0/Test_2.scala diff --git a/tests/pos-macros/forwardCompat-3.1/Macro_1_c3.1.0.scala b/tests/pos-macros/backwardCompat-3.1/Macro_1_c3.1.0.scala similarity index 100% rename from tests/pos-macros/forwardCompat-3.1/Macro_1_c3.1.0.scala rename to tests/pos-macros/backwardCompat-3.1/Macro_1_c3.1.0.scala diff --git a/tests/pos-macros/forwardCompat-3.1/Test_2.scala b/tests/pos-macros/backwardCompat-3.1/Test_2.scala similarity index 100% rename from tests/pos-macros/forwardCompat-3.1/Test_2.scala rename to tests/pos-macros/backwardCompat-3.1/Test_2.scala diff --git a/tests/pos-macros/backwardCompat-3.0/Macro_1_r3.0.scala b/tests/pos-macros/forwardCompat-3.0/Macro_1_r3.0.scala similarity index 100% rename from tests/pos-macros/backwardCompat-3.0/Macro_1_r3.0.scala rename to tests/pos-macros/forwardCompat-3.0/Macro_1_r3.0.scala diff --git a/tests/pos-macros/backwardCompat-3.0/Test_2_c3.0.0.scala b/tests/pos-macros/forwardCompat-3.0/Test_2_c3.0.0.scala similarity index 100% rename from tests/pos-macros/backwardCompat-3.0/Test_2_c3.0.0.scala rename to tests/pos-macros/forwardCompat-3.0/Test_2_c3.0.0.scala