Skip to content

Commit 5755160

Browse files
Add test to check lazyness of default value
1 parent da9bdfb commit 5755160

4 files changed

+33
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
42
2+
OK
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Sample main method
2+
object myProgram:
3+
4+
@main def alwaysPassParam(forbiddenParam: Int = throw new IllegalStateException("This should not be evaluated!")): Unit =
5+
println(forbiddenParam)
6+
7+
end myProgram
8+
9+
object Test:
10+
def hasCauseIllegalStateException(e: Throwable): Boolean =
11+
e.getCause match {
12+
case null => false
13+
case _: IllegalStateException => true
14+
case e: Throwable => hasCauseIllegalStateException(e)
15+
}
16+
17+
def callMain(args: Array[String]): Unit =
18+
val clazz = Class.forName("alwaysPassParam")
19+
val method = clazz.getMethod("main", classOf[Array[String]])
20+
method.invoke(null, args)
21+
22+
def main(args: Array[String]): Unit =
23+
callMain(Array("42"))
24+
try {
25+
callMain(Array())
26+
println("This should not be printed")
27+
}
28+
catch {
29+
case e: Exception if hasCauseIllegalStateException(e) => println("OK")
30+
}
31+
end Test

0 commit comments

Comments
 (0)