Scala compiler fails to infer the return type when there's an explicit return statement

This commit is contained in:
Artur Mkrtchyan 2014-12-20 23:03:25 +01:00
parent fe856e7117
commit 6027c90c90

View File

@ -199,7 +199,7 @@ weirdSum(2, 4) // => 16
// The return keyword exists in Scala, but it only returns from the inner-most // The return keyword exists in Scala, but it only returns from the inner-most
// def that surrounds it. It has no effect on anonymous functions. For example: // def that surrounds it. It has no effect on anonymous functions. For example:
def foo(x: Int) = { def foo(x: Int): Int = {
val anonFunc: Int => Int = { z => val anonFunc: Int => Int = { z =>
if (z > 5) if (z > 5)
return z // This line makes z the return value of foo! return z // This line makes z the return value of foo!