Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-Wstrict-tailrec possible general recursion
- Loading branch information
Showing
4 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
t4649b.scala:8: error: could not optimize @tailrec annotated method lazyFilter: it contains a recursive call not in tail position | ||
case h #:: t => if (p(h)) h #:: lazyFilter(t, p) else lazyFilter(t, p) // error | ||
^ | ||
t4649b.scala:21: error: could not optimize @tailrec annotated method f: it contains a recursive call not in tail position | ||
val g: Int => Int = f(_) // error | ||
^ | ||
2 errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//> using options -Wstrict-tailrec | ||
|
||
import annotation.tailrec | ||
|
||
object Test { | ||
@tailrec | ||
def lazyFilter[E](s: LazyList[E], p: E => Boolean): LazyList[E] = s match { | ||
case h #:: t => if (p(h)) h #:: lazyFilter(t, p) else lazyFilter(t, p) // error | ||
} | ||
|
||
@tailrec | ||
def f(i: Int): Int = | ||
if (i <= 0) i | ||
/* not optimized | ||
else if (i == 27) { | ||
val x = f(i - 1) | ||
x | ||
} | ||
*/ | ||
else if (i == 42) { | ||
val g: Int => Int = f(_) // error | ||
f(i - 1) | ||
} | ||
else f(i - 1) | ||
} |