-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#20105: Adding a warning to the case where nested named definitions c…
…ontain non-tail recursive calls. Code will now compile where a child def calls the parent def in a non-tail position (with the warning). Code will no longer compile if all calls to a @tailrec method are in named child methods (as these do not tail recurse).
- Loading branch information
Lucy Martin
committed
Jun 19, 2024
1 parent
133c14a
commit 01ada74
Showing
8 changed files
with
83 additions
and
4 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
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,10 @@ | ||
-- [E199] Syntax Warning: tests/neg/i20105.scala:6:9 ------------------------------------------------------------------- | ||
6 | foo() | ||
| ^^^^^ | ||
| The tail recursive def foo contains a recursive call inside the non-inlined inner def bar | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E097] Syntax Error: tests/neg/i20105.scala:3:4 --------------------------------------------------------------------- | ||
3 |def foo(): Unit = // error | ||
| ^ | ||
| TailRec optimisation not applicable, method foo contains no recursive calls |
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,9 @@ | ||
import scala.annotation.tailrec | ||
@tailrec | ||
def foo(): Unit = // error | ||
def bar(): Unit = | ||
if (???) | ||
foo() | ||
else | ||
bar() | ||
bar() |
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,6 @@ | ||
-- [E199] Syntax Warning: tests/warn/i20105.scala:6:9 ------------------------------------------------------------------ | ||
6 | foo() // warn | ||
| ^^^^^ | ||
| The tail recursive def foo contains a recursive call inside the non-inlined inner def bar | ||
| | ||
| longer explanation available when compiling with `-explain` |
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,10 @@ | ||
import scala.annotation.tailrec | ||
@tailrec | ||
def foo(): Unit = | ||
def bar(): Unit = | ||
if (???) | ||
foo() // warn | ||
else | ||
bar() | ||
bar() | ||
foo() |