-
-
Notifications
You must be signed in to change notification settings - Fork 661
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[analyzer] deal with unreachable block in binops
closes #11402
- Loading branch information
Showing
2 changed files
with
97 additions
and
10 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,78 @@ | ||
package unit.issues; | ||
|
||
class Issue11402 extends Test { | ||
static function binopWithReturn() { | ||
var ans = Std.string(return "") + ""; | ||
} | ||
|
||
static function binopWithThrow() { | ||
var ans = Std.string(throw "") + ""; | ||
} | ||
|
||
static function binopWithBreak() { | ||
while (true) { | ||
var ans = Std.string(break) + ""; | ||
return "b"; | ||
} | ||
return "a"; | ||
} | ||
|
||
static function binopWithContinue() { | ||
var a = 0; | ||
while (true) { | ||
if (a++ > 0) { | ||
return "a"; | ||
} | ||
var ans = Std.string(continue) + ""; | ||
return "b"; | ||
} | ||
} | ||
|
||
static function arrayWithReturn() { | ||
var ans = [Std.string(return "")][0]; | ||
} | ||
|
||
static function arrayWithThrow() { | ||
var ans = [Std.string(throw "")][0]; | ||
} | ||
|
||
static function arrayWithBreak() { | ||
while (true) { | ||
var ans = [Std.string(break)][0]; | ||
return "b"; | ||
} | ||
return "a"; | ||
} | ||
|
||
static function arrayWithContinue() { | ||
var a = 0; | ||
while (true) { | ||
if (a++ > 0) { | ||
return "a"; | ||
} | ||
var ans = [Std.string(continue)][0]; | ||
return "b"; | ||
} | ||
} | ||
|
||
static function originalExample() { | ||
var cells = [1, 2, 3]; | ||
var ans = ""; | ||
ans += '${cells.length} cell${if (cells.length == 1) {return "";} else {return "s";}}.\n'; | ||
return ans; | ||
} | ||
|
||
function test() { | ||
eq("", binopWithReturn()); | ||
exc(binopWithThrow); | ||
eq("a", binopWithBreak()); | ||
eq("a", binopWithContinue()); | ||
|
||
eq("", arrayWithReturn()); | ||
exc(arrayWithThrow); | ||
eq("a", arrayWithBreak()); | ||
eq("a", arrayWithContinue()); | ||
|
||
eq("s", originalExample()); | ||
} | ||
} |