summaryrefslogtreecommitdiff
path: root/tests/language-feature/error-handling/throw-without-throws.slang
diff options
context:
space:
mode:
authorJulius Ikkala <julius.ikkala@gmail.com>2025-05-23 22:27:37 +0300
committerGitHub <noreply@github.com>2025-05-23 12:27:37 -0700
commit57c3f938221c427b78da7087f8a832ba4a271a7c (patch)
treee9a6d26278dc1ad75b222ac4fc9b7a1d8449e576 /tests/language-feature/error-handling/throw-without-throws.slang
parentd108bfa677c70808b32bd77e93637ed34c19c75d (diff)
Implement throw & catch statements (#6916)
* Implement throw statement It already existed in the IR, so only parsing, checking and lowering was missing. * Initial catch implementation Likely very broken. * Error out when catch() isn't last in scope * Prevent accessing variables from scope preceding catch As those may actually not be available at that point. * Add IError and use it in Result type lowering * Add diagnostic tests * Allow caught throws in non-throw functions * Fix catch propagating between functions & SPIR-V merge issue * Add test for non-trivial error types * Fix MSVC build * Fix invalid value type from Result lowering * Also lower error handling in templates * Lower result types only after specialization * Attempt to disambiguate error enums by witness table * Revert matching by witness, types should be distinct too * Don't assert valueField when getting Result's error value It may not exist if the function returns void, but getting the error value is still legitimate. * Update tests for new error numbers & get rid of expected.txt * Change catch lowering to resemble breaking a loop ... To make SPIR-V happy. * Fix dead catch blocks and invalid cached dominator tree * More SPIR-V adjustment * Lower catch as two nested loops * Add defer interaction test and revert broken defer changes * Fix enum type when throwing literals * Cleanup and bikeshedding * Document error handling mechanism * Fix table of contents * Use boolean tag in Result<T, E> * Use anyValue storage for Result<T,E> * Remove IError * Fix formatting * Eradicate success values from docs and tests * Use parseModernParamDecl for catch parameter * Implement do-catch syntax * Implement catch-all * Fix formatting * Fix marshalling native calls that throw --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tests/language-feature/error-handling/throw-without-throws.slang')
-rw-r--r--tests/language-feature/error-handling/throw-without-throws.slang19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/language-feature/error-handling/throw-without-throws.slang b/tests/language-feature/error-handling/throw-without-throws.slang
new file mode 100644
index 000000000..e37198b82
--- /dev/null
+++ b/tests/language-feature/error-handling/throw-without-throws.slang
@@ -0,0 +1,19 @@
+//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK):
+enum MyError
+{
+ Fail
+}
+
+int g() throws MyError
+{
+ throw MyError.Fail;
+}
+
+void f()
+{
+ let n = try g();
+ throw MyError.Fail;
+}
+
+// CHECK: error 30093
+// CHECK: error 30115