-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2029 from unisonweb/feature/exceptions
Allow `Exception` ability to be used by main functions
- unboxed-arithmetic-debug-build
- unboxed-arithmetic-build
- trunk-build
- stack-assertions-build
- release/0.5.36
- release/0.5.35
- release/0.5.34
- release/0.5.33
- release/0.5.32
- release/0.5.31
- release/0.5.29
- release/0.5.28
- release/0.5.27
- release/0.5.26
- release/0.5.25
- release/0.5.24
- release/0.5.23
- release/0.5.22
- release/0.5.21
- release/0.5.20
- release/0.5.19
- release/0.5.18
- release/0.5.17
- release/0.5.16
- release/0.5.15
- release/0.5.14
- release/0.5.13
- release/0.5.12
- release/0.5.11
- release/M5
- release/M5j
- release/M5i
- release/M5h
- release/M5g
- release/M5f
- release/M5e
- release/M5d
- release/M5c
- release/M5b
- release/M5a
- release/M4
- release/M4i
- release/M4h
- release/M4g
- release/M4f
- release/M4e
- release/M4d
- release/M4c
- release/M4b
- release/M4a
- release/M3
- release/M2l
- release/M2k
- release/M2j
- release/M2i
- release/M2h
- pattern-compilation-pr-5557
- pattern-compilation-pr-5557-build
- mac-arm-build-build
- lockstep-stack-build
- lib-install-build
- last-working-chez
- interp-inlining-build
- inlining-experiments-build
- fix-segfault-build
- fix-launcher-script-2-build
- dev/M4
- dev/M3
- dev/M2l
- cloud-build
- better-bools-build
- M4a
Showing
17 changed files
with
605 additions
and
393 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,46 @@ | ||
|
||
A simple transcript to test the use of exceptions that bubble to the top level. | ||
|
||
```ucm:hide | ||
.> builtins.merge | ||
``` | ||
|
||
FYI, here are the `Exception` and `Failure` types: | ||
|
||
```ucm | ||
.> view Exception Failure | ||
``` | ||
|
||
Here's a sample program just to verify that the typechecker allows `run` to throw exceptions: | ||
|
||
```unison | ||
use builtin IO Exception Test.Result | ||
main : '{IO, Exception} () | ||
main _ = () | ||
mytest : '{IO, Exception} [Test.Result] | ||
mytest _ = [Ok "Great"] | ||
``` | ||
|
||
```ucm | ||
.> run main | ||
.> add | ||
.> io.test mytest | ||
``` | ||
|
||
Now a test to show the handling of uncaught exceptions: | ||
|
||
```unison | ||
main2 = '(error "oh noes!" ()) | ||
error : Text -> a ->{Exception} x | ||
error msg a = | ||
builtin.Exception.raise (Failure (typeLink RuntimeError) msg (Any a)) | ||
unique type RuntimeError = | ||
``` | ||
|
||
```ucm:error | ||
.> run main2 | ||
``` |
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,96 @@ | ||
|
||
A simple transcript to test the use of exceptions that bubble to the top level. | ||
|
||
FYI, here are the `Exception` and `Failure` types: | ||
|
||
```ucm | ||
.> view Exception Failure | ||
ability builtin.Exception where | ||
raise : Failure ->{builtin.Exception} x | ||
unique type builtin.io2.Failure | ||
= Failure Type Text Any | ||
``` | ||
Here's a sample program just to verify that the typechecker allows `run` to throw exceptions: | ||
|
||
```unison | ||
use builtin IO Exception Test.Result | ||
main : '{IO, Exception} () | ||
main _ = () | ||
mytest : '{IO, Exception} [Test.Result] | ||
mytest _ = [Ok "Great"] | ||
``` | ||
|
||
```ucm | ||
I found and typechecked these definitions in scratch.u. If you | ||
do an `add` or `update`, here's how your codebase would | ||
change: | ||
⍟ These new definitions are ok to `add`: | ||
main : '{IO, Exception} () | ||
mytest : '{IO, Exception} [Result] | ||
``` | ||
```ucm | ||
.> run main | ||
.> add | ||
⍟ I've added these definitions: | ||
main : '{IO, Exception} () | ||
mytest : '{IO, Exception} [Result] | ||
.> io.test mytest | ||
New test results: | ||
◉ mytest Great | ||
✅ 1 test(s) passing | ||
Tip: Use view mytest to view the source of a test. | ||
``` | ||
Now a test to show the handling of uncaught exceptions: | ||
|
||
```unison | ||
main2 = '(error "oh noes!" ()) | ||
error : Text -> a ->{Exception} x | ||
error msg a = | ||
builtin.Exception.raise (Failure (typeLink RuntimeError) msg (Any a)) | ||
unique type RuntimeError = | ||
``` | ||
|
||
```ucm | ||
I found and typechecked these definitions in scratch.u. If you | ||
do an `add` or `update`, here's how your codebase would | ||
change: | ||
⍟ These new definitions are ok to `add`: | ||
unique type RuntimeError | ||
error : Text -> a ->{Exception} x | ||
main2 : '{Exception} r | ||
``` | ||
```ucm | ||
.> run main2 | ||
💔💥 | ||
The program halted with an unhandled exception: | ||
builtin.io2.Failure.Failure | ||
(typeLink RuntimeError) "oh noes!" !builtin.Any.Any | ||
``` |