From f3375078521ee374c9c3608cc1a65ae96cb36039 Mon Sep 17 00:00:00 2001 From: Jamie Thompson Date: Fri, 15 Nov 2024 19:50:53 +0100 Subject: [PATCH] test clause interleaving and value class --- tests/neg/unroll-clause-interleaving.check | 7 +++++++ tests/neg/unroll-clause-interleaving.scala | 10 ++++++++++ .../unroll-clause-interleaving/Test_4.scala | 7 +++++++ .../Unrolled_1.scala | 14 ++++++++++++++ .../Unrolled_2.scala | 16 ++++++++++++++++ .../Unrolled_3.scala | 18 ++++++++++++++++++ tests/run/unroll-value-class/Test_4.scala | 7 +++++++ tests/run/unroll-value-class/Unrolled_1.scala | 13 +++++++++++++ tests/run/unroll-value-class/Unrolled_2.scala | 15 +++++++++++++++ tests/run/unroll-value-class/Unrolled_3.scala | 17 +++++++++++++++++ 10 files changed, 124 insertions(+) create mode 100644 tests/neg/unroll-clause-interleaving.check create mode 100644 tests/neg/unroll-clause-interleaving.scala create mode 100644 tests/run/unroll-clause-interleaving/Test_4.scala create mode 100644 tests/run/unroll-clause-interleaving/Unrolled_1.scala create mode 100644 tests/run/unroll-clause-interleaving/Unrolled_2.scala create mode 100644 tests/run/unroll-clause-interleaving/Unrolled_3.scala create mode 100644 tests/run/unroll-value-class/Test_4.scala create mode 100644 tests/run/unroll-value-class/Unrolled_1.scala create mode 100644 tests/run/unroll-value-class/Unrolled_2.scala create mode 100644 tests/run/unroll-value-class/Unrolled_3.scala diff --git a/tests/neg/unroll-clause-interleaving.check b/tests/neg/unroll-clause-interleaving.check new file mode 100644 index 000000000000..eea8a7383e09 --- /dev/null +++ b/tests/neg/unroll-clause-interleaving.check @@ -0,0 +1,7 @@ +-- Error: tests/neg/unroll-clause-interleaving.scala:6:12 -------------------------------------------------------------- +6 | final def foo(@unroll x: Int = 0)[T](// error + | ^ + | Cannot have multiple parameter lists containing `@unroll` annotation +7 | s: T, +8 | @unroll y: Boolean = true, +9 | ): String = "" + x + s + y diff --git a/tests/neg/unroll-clause-interleaving.scala b/tests/neg/unroll-clause-interleaving.scala new file mode 100644 index 000000000000..c40941320db1 --- /dev/null +++ b/tests/neg/unroll-clause-interleaving.scala @@ -0,0 +1,10 @@ +//> using options -experimental + +import scala.annotation.unroll + +class Unrolled { + final def foo(@unroll x: Int = 0)[T](// error + s: T, + @unroll y: Boolean = true, + ): String = "" + x + s + y +} diff --git a/tests/run/unroll-clause-interleaving/Test_4.scala b/tests/run/unroll-clause-interleaving/Test_4.scala new file mode 100644 index 000000000000..4090469bb716 --- /dev/null +++ b/tests/run/unroll-clause-interleaving/Test_4.scala @@ -0,0 +1,7 @@ +//> using options -experimental + +@main def Test: Unit = + val u = Unrolled() + TestV1().test(u) + TestV2().test(u) + TestV3().test(u) diff --git a/tests/run/unroll-clause-interleaving/Unrolled_1.scala b/tests/run/unroll-clause-interleaving/Unrolled_1.scala new file mode 100644 index 000000000000..7954acc15680 --- /dev/null +++ b/tests/run/unroll-clause-interleaving/Unrolled_1.scala @@ -0,0 +1,14 @@ +//> using options -experimental + +import scala.annotation.unroll + +class Unrolled { + final def foo(x: Int)[T]( + s: T, + ): String = "" + x + s +} + +class TestV1 { + def test(u: Unrolled): Unit = + assert(u.foo(0)("foo").startsWith("0foo")) +} diff --git a/tests/run/unroll-clause-interleaving/Unrolled_2.scala b/tests/run/unroll-clause-interleaving/Unrolled_2.scala new file mode 100644 index 000000000000..5adc2bc924ec --- /dev/null +++ b/tests/run/unroll-clause-interleaving/Unrolled_2.scala @@ -0,0 +1,16 @@ +//> using options -experimental + +import scala.annotation.unroll + +class Unrolled { + final def foo(x: Int)[T]( + s: T, + @unroll y: Boolean = true, + ): String = "" + x + s + y +} + +class TestV2 { + def test(u: Unrolled): Unit = + assert(u.foo(0)("foo").startsWith("0footrue")) + assert(u.foo(0)("foo", false).startsWith("0foofalse")) +} diff --git a/tests/run/unroll-clause-interleaving/Unrolled_3.scala b/tests/run/unroll-clause-interleaving/Unrolled_3.scala new file mode 100644 index 000000000000..e23b9d12843a --- /dev/null +++ b/tests/run/unroll-clause-interleaving/Unrolled_3.scala @@ -0,0 +1,18 @@ +//> using options -experimental + +import scala.annotation.unroll + +class Unrolled { + final def foo(x: Int)[T]( + s: T, + @unroll y: Boolean = true, + @unroll i: Int = 0, + ): String = "" + x + s + y + i +} + +class TestV3 { + def test(u: Unrolled): Unit = + assert(u.foo(0)("foo").startsWith("0footrue0")) + assert(u.foo(0)("foo", false).startsWith("0foofalse0")) + assert(u.foo(0)("foo", false, 1).startsWith("0foofalse1")) +} diff --git a/tests/run/unroll-value-class/Test_4.scala b/tests/run/unroll-value-class/Test_4.scala new file mode 100644 index 000000000000..98d7ff7e3f64 --- /dev/null +++ b/tests/run/unroll-value-class/Test_4.scala @@ -0,0 +1,7 @@ +//> using options -experimental + +@main def Test: Unit = + val u = Unrolled(0) + TestV1().test(u) + TestV2().test(u) + TestV3().test(u) diff --git a/tests/run/unroll-value-class/Unrolled_1.scala b/tests/run/unroll-value-class/Unrolled_1.scala new file mode 100644 index 000000000000..86d12831b78f --- /dev/null +++ b/tests/run/unroll-value-class/Unrolled_1.scala @@ -0,0 +1,13 @@ +//> using options -experimental + +import scala.annotation.unroll + +class Unrolled(val x: Int) extends AnyVal { + final def foo( + s: String, + ): String = "" + x + s +} + +class TestV1: + def test(u: Unrolled): Unit = + assert(u.foo("foo").startsWith("0foo")) diff --git a/tests/run/unroll-value-class/Unrolled_2.scala b/tests/run/unroll-value-class/Unrolled_2.scala new file mode 100644 index 000000000000..1be3f4ee38b6 --- /dev/null +++ b/tests/run/unroll-value-class/Unrolled_2.scala @@ -0,0 +1,15 @@ +//> using options -experimental + +import scala.annotation.unroll + +class Unrolled(val x: Int) extends AnyVal { + final def foo( + s: String, + @unroll y: Boolean = true, + ): String = "" + x + s + y +} + +class TestV2: + def test(u: Unrolled): Unit = + assert(u.foo("foo").startsWith("0footrue")) + assert(u.foo("foo", false).startsWith("0foofalse")) diff --git a/tests/run/unroll-value-class/Unrolled_3.scala b/tests/run/unroll-value-class/Unrolled_3.scala new file mode 100644 index 000000000000..05e5399bbe53 --- /dev/null +++ b/tests/run/unroll-value-class/Unrolled_3.scala @@ -0,0 +1,17 @@ +//> using options -experimental + +import scala.annotation.unroll + +class Unrolled(val x: Int) extends AnyVal { + final def foo( + s: String, + @unroll y: Boolean = true, + @unroll i: Int = 0 + ): String = "" + x + s + y + i +} + +class TestV3: + def test(u: Unrolled): Unit = + assert(u.foo("foo").startsWith("0footrue0")) + assert(u.foo("foo", false).startsWith("0foofalse0")) + assert(u.foo("foo", false, 1).startsWith("0foofalse1"))