Skip to content

Commit

Permalink
test clause interleaving and value class
Browse files Browse the repository at this point in the history
  • Loading branch information
bishabosha committed Dec 20, 2024
1 parent 78fbf04 commit f337507
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/neg/unroll-clause-interleaving.check
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions tests/neg/unroll-clause-interleaving.scala
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 7 additions & 0 deletions tests/run/unroll-clause-interleaving/Test_4.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//> using options -experimental

@main def Test: Unit =
val u = Unrolled()
TestV1().test(u)
TestV2().test(u)
TestV3().test(u)
14 changes: 14 additions & 0 deletions tests/run/unroll-clause-interleaving/Unrolled_1.scala
Original file line number Diff line number Diff line change
@@ -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"))
}
16 changes: 16 additions & 0 deletions tests/run/unroll-clause-interleaving/Unrolled_2.scala
Original file line number Diff line number Diff line change
@@ -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"))
}
18 changes: 18 additions & 0 deletions tests/run/unroll-clause-interleaving/Unrolled_3.scala
Original file line number Diff line number Diff line change
@@ -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"))
}
7 changes: 7 additions & 0 deletions tests/run/unroll-value-class/Test_4.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//> using options -experimental

@main def Test: Unit =
val u = Unrolled(0)
TestV1().test(u)
TestV2().test(u)
TestV3().test(u)
13 changes: 13 additions & 0 deletions tests/run/unroll-value-class/Unrolled_1.scala
Original file line number Diff line number Diff line change
@@ -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"))
15 changes: 15 additions & 0 deletions tests/run/unroll-value-class/Unrolled_2.scala
Original file line number Diff line number Diff line change
@@ -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"))
17 changes: 17 additions & 0 deletions tests/run/unroll-value-class/Unrolled_3.scala
Original file line number Diff line number Diff line change
@@ -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"))

0 comments on commit f337507

Please sign in to comment.