-
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.
Fix bug in capture analysis of closures
- Loading branch information
1 parent
31b6523
commit 41e9816
Showing
2 changed files
with
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class BreakControl extends Throwable | ||
|
||
object Breaks: | ||
private val breakException = new BreakControl | ||
|
||
def breakable(op: => Unit): Unit = | ||
try op catch { case ex: BreakControl if ex eq breakException => } | ||
|
||
def break(): Nothing = throw breakException | ||
|
||
object A: | ||
val n = foo("hello") | ||
def foo(s: String): Int = | ||
val len = s.length | ||
var i = 0 | ||
|
||
while (i < len) { | ||
Breaks.breakable { | ||
val c = s.charAt(i) | ||
|
||
if c == '\n' then Breaks.break() | ||
} | ||
i += 1 | ||
} | ||
|
||
i |