|
| 1 | +//> using options -experimental |
| 2 | + |
| 3 | +import scala.annotation.unroll |
| 4 | +import scala.deriving.Mirror |
| 5 | + |
| 6 | +class Unrolled { |
| 7 | + final def foo( |
| 8 | + s: String, |
| 9 | + @unroll y: Boolean = true, |
| 10 | + @unroll i: Int = 0, |
| 11 | + @unroll c: Char = '?'): String = s + y + i + c |
| 12 | +} |
| 13 | + |
| 14 | +class Outer { |
| 15 | + class Unrolled { |
| 16 | + final def bar( |
| 17 | + s: String, |
| 18 | + @unroll y: Boolean = true, |
| 19 | + @unroll i: Int = 0, |
| 20 | + @unroll c: Char = '?'): String = s + y + i + c |
| 21 | + } |
| 22 | + |
| 23 | + case class UnrolledCase( |
| 24 | + s: String, |
| 25 | + @unroll y: Boolean = true, |
| 26 | + @unroll i: Int = 0, |
| 27 | + @unroll c: Char = '?') { |
| 28 | + def baz: String = s + y + i + c |
| 29 | + } |
| 30 | + |
| 31 | + class UnrolledSecondary { |
| 32 | + private var msg = "" |
| 33 | + |
| 34 | + def qux: String = msg |
| 35 | + |
| 36 | + def this( |
| 37 | + s: String, |
| 38 | + @unroll y: Boolean = true, |
| 39 | + @unroll i: Int = 0, |
| 40 | + @unroll c: Char = '?') = { |
| 41 | + this() |
| 42 | + msg = s + y + i + c |
| 43 | + } |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +@main def Test: Unit = |
| 48 | + assert(Unrolled().foo("foo") == "footrue0?") |
| 49 | + assert(Unrolled().foo("foo", false) == "foofalse0?") |
| 50 | + assert(Unrolled().foo("foo", false, 1) == "foofalse1?") |
| 51 | + assert(Unrolled().foo("foo", false, 1, '@') == "foofalse1@") |
| 52 | + val outer = new Outer() |
| 53 | + assert(new outer.Unrolled().bar("bar") == "bartrue0?") |
| 54 | + assert(new outer.Unrolled().bar("bar", false) == "barfalse0?") |
| 55 | + assert(new outer.Unrolled().bar("bar", false, 1) == "barfalse1?") |
| 56 | + assert(new outer.Unrolled().bar("bar", false, 1, '@') == "barfalse1@") |
| 57 | + assert(outer.UnrolledCase.apply("baz").baz == "baztrue0?") |
| 58 | + assert(outer.UnrolledCase.apply("baz", false).baz == "bazfalse0?") |
| 59 | + assert(outer.UnrolledCase.apply("baz", false, 1).baz == "bazfalse1?") |
| 60 | + assert(outer.UnrolledCase.apply("baz", false, 1, '@').baz == "bazfalse1@") |
| 61 | + assert((new outer.UnrolledCase("baz")).baz == "baztrue0?") |
| 62 | + assert((new outer.UnrolledCase("baz", false)).baz == "bazfalse0?") |
| 63 | + assert((new outer.UnrolledCase("baz", false, 1)).baz == "bazfalse1?") |
| 64 | + assert((new outer.UnrolledCase("baz", false, 1, '@')).baz == "bazfalse1@") |
| 65 | + assert(summon[Mirror.Of[outer.UnrolledCase]].fromProduct(Tuple("baz")).baz == "baztrue0?") |
| 66 | + assert(summon[Mirror.Of[outer.UnrolledCase]].fromProduct(("baz", false)).baz == "bazfalse0?") |
| 67 | + assert(summon[Mirror.Of[outer.UnrolledCase]].fromProduct(("baz", false, 1)).baz == "bazfalse1?") |
| 68 | + assert(summon[Mirror.Of[outer.UnrolledCase]].fromProduct(("baz", false, 1, '@')).baz == "bazfalse1@") |
| 69 | + assert(new outer.UnrolledSecondary("qux").qux == "quxtrue0?") |
| 70 | + assert(new outer.UnrolledSecondary("qux", false).qux == "quxfalse0?") |
| 71 | + assert(new outer.UnrolledSecondary("qux", false, 1).qux == "quxfalse1?") |
| 72 | + assert(new outer.UnrolledSecondary("qux", false, 1, '@').qux == "quxfalse1@") |
0 commit comments