Skip to content

Commit bbf0f0c

Browse files
add tests for some edge cases
1 parent a1d6bc2 commit bbf0f0c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/run/mirror-defaultArgument/test.scala

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,37 @@ object Test extends App:
2121
throw IllegalStateException("There should be no default argument")
2222
catch
2323
case ex: NoSuchElementException => assert(ex.getMessage == "0") // Ok
24+
25+
26+
case class WithCompanion(s: String = "hello")
27+
case object WithCompanion // => mirrors must be anonymous
28+
29+
val m2 = summon[Mirror.Of[WithCompanion]]
30+
assert(m2 ne WithCompanion)
31+
assert(m2.defaultArgument(0) == "hello")
32+
33+
34+
class Outer(val i: Int) {
35+
36+
case class Inner(x: Int, y: Int = i + 1)
37+
case object Inner
38+
39+
val m3 = summon[Mirror.Of[Inner]]
40+
assert(m3.defaultArgument(1) == i + 1)
41+
42+
def localTest(d: Double): Unit = {
43+
case class Local(x: Int = i, y: Double = d, z: Double = i + d)
44+
case object Local
45+
46+
val m4 = summon[Mirror.Of[Local]]
47+
assert(m4.defaultArgument(0) == i)
48+
assert(m4.defaultArgument(1) == d)
49+
assert(m4.defaultArgument(2) == i + d)
50+
}
51+
52+
}
53+
54+
val outer = Outer(3)
55+
val m5 = summon[Mirror.Of[outer.Inner]]
56+
assert(m5.defaultArgument(1) == 3 + 1)
57+
outer.localTest(9d)

0 commit comments

Comments
 (0)