Files
sx/examples/errors/1003-errors-raise-rejections.sx
agra 66bdc70bf1 test: group examples into per-category folders
Move examples/*.sx and their expected/ snapshots into per-category
subfolders (examples/<category>/...). Folder = leading filename token,
with ffi-objc/ffi-jni kept whole; filenames are unchanged. The corpus
runner and LSP sweep now discover each category's expected/ dir, while
issues/ stays flat. Example 1058's repo-root-relative companion import
is made file-relative. Path strings embedded in 164 snapshots were
regenerated (path-only changes). Test-layout docs in CLAUDE.md updated.
2026-06-21 14:41:34 +03:00

33 lines
1.2 KiB
Plaintext

// `raise` rejections (ERR step E1.3):
// - `raise` is only valid inside a failable function,
// - a literal `raise error.X` must name a tag in the function's set,
// - a variable `raise e` must carry a set that is a subset of the
// function's set.
// The positive case lives in `examples/219-raise.sx`. Parse-time rejections
// (`raise` in expression position / inside `defer` / `onfail`) are covered by
// the inline parser tests.
#import "modules/std.sx";
ParseErr :: error { BadDigit, Overflow }
OtherErr :: error { Weird }
// Literal tag not in the declared set.
bad_tag :: () -> !ParseErr {
raise error.NotInSet; // error: NotInSet not in ParseErr
}
// Variable whose error set is not a subset of the function's set.
makes_other :: () -> !OtherErr { return; }
relay :: () -> !ParseErr {
e := makes_other(); // e : OtherErr
raise e; // error: OtherErr not subset of ParseErr
}
main :: () -> i32 {
x := bad_tag(); // force bad_tag to lower
y := relay(); // force relay to lower
raise error.BadDigit; // error: main (-> i32) is not failable
return 0;
}