-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
panic
builtin function (#757)
Closes #756 --------- Co-authored-by: Mark Koch <[email protected]> Co-authored-by: Mark Koch <[email protected]>
- Loading branch information
1 parent
70c8fcf
commit 4ae3032
Showing
13 changed files
with
177 additions
and
2 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
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 @@ | ||
Error: No panic message (at $FILE:7:4) | ||
| | ||
5 | @compile_guppy | ||
6 | def foo(x: int) -> None: | ||
7 | panic() | ||
| ^^^^^^^ Missing message argument to panic call | ||
|
||
Note: Add a message: `panic("message")` | ||
|
||
Guppy compilation failed due to 1 previous error |
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 @@ | ||
from guppylang.std.builtins import panic | ||
from tests.util import compile_guppy | ||
|
||
|
||
@compile_guppy | ||
def foo(x: int) -> None: | ||
panic() |
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,8 @@ | ||
Error: Expected a string literal (at $FILE:7:10) | ||
| | ||
5 | @compile_guppy | ||
6 | def foo(x: int) -> None: | ||
7 | panic((), x) | ||
| ^^ Expected a string literal | ||
|
||
Guppy compilation failed due to 1 previous error |
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 @@ | ||
from guppylang.std.builtins import panic | ||
from tests.util import compile_guppy | ||
|
||
|
||
@compile_guppy | ||
def foo(x: int) -> None: | ||
panic((), x) |
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,8 @@ | ||
Error: Expected a string literal (at $FILE:7:10) | ||
| | ||
5 | @compile_guppy | ||
6 | def foo(y: bool) -> None: | ||
7 | panic("foo" + "bar", y) | ||
| ^^^^^^^^^^^^^ Expected a string literal | ||
|
||
Guppy compilation failed due to 1 previous error |
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 @@ | ||
from guppylang.std.builtins import panic | ||
from tests.util import compile_guppy | ||
|
||
|
||
@compile_guppy | ||
def foo(y: bool) -> None: | ||
panic("foo" + "bar", y) |
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,38 @@ | ||
from guppylang import GuppyModule, guppy | ||
from guppylang.std.builtins import panic | ||
from tests.util import compile_guppy | ||
|
||
|
||
def test_basic(validate): | ||
@compile_guppy | ||
def main() -> None: | ||
panic("I panicked!") | ||
|
||
validate(main) | ||
|
||
|
||
def test_discard(validate): | ||
@compile_guppy | ||
def main() -> None: | ||
a = 1 + 2 | ||
panic("I panicked!", False, a) | ||
|
||
validate(main) | ||
|
||
|
||
def test_value(validate): | ||
module = GuppyModule("test") | ||
|
||
@guppy(module) | ||
def foo() -> int: | ||
return panic("I panicked!") | ||
|
||
@guppy(module) | ||
def bar() -> tuple[int, float]: | ||
return panic("I panicked!") | ||
|
||
@guppy(module) | ||
def baz() -> None: | ||
return panic("I panicked!") | ||
|
||
validate(module.compile()) |
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