diff options
author | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-03-17 02:12:02 +0200 |
---|---|---|
committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-03-17 02:12:02 +0200 |
commit | 78bf3e039d77e3eb0d5e394273adb69b2b70a76d (patch) | |
tree | 0ed6f2058e348dbd18b0baa9c4ee442206191096 /examples/own.fwd | |
parent | 2367a8b63c3bcfe62d1aaf7d82c0ab3622f3b16c (diff) | |
download | fwd-78bf3e039d77e3eb0d5e394273adb69b2b70a76d.tar.gz fwd-78bf3e039d77e3eb0d5e394273adb69b2b70a76d.zip |
detect leaks
Diffstat (limited to 'examples/own.fwd')
-rw-r--r-- | examples/own.fwd | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/examples/own.fwd b/examples/own.fwd new file mode 100644 index 0000000..6634886 --- /dev/null +++ b/examples/own.fwd @@ -0,0 +1,33 @@ +do_something((auto) a); +consume(auto a); + +main() +{ + do_something() => auto a; + do_something() => auto b; + !> e { + /* if do_something() fails, a is still alive, so we must kill + * it. However, we might enter this error block after the + * callback to do_something() was run, and a might've already + * been moved. own just checks if we still own the resource and + * executes the block. + * + * admittedly, purely syntactically it would look like b is + * already alive at this point, but since it's actually within + * the implicit closure, it is not. Might play around with ordering + * the error block to come before implicit closures... + */ + own a {consume(a);} + error e + } + + consume(a); + !> e { + /* if consume fails, b is still alive, but either this error + * block runs (and throws an error) or the next consume is run, + * so own is not necessary here */ + consume(b); + error e + } + consume(b); +} |