aboutsummaryrefslogtreecommitdiff
path: root/test/data/static.yx
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-07-09 16:29:22 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-07-09 16:29:22 +0200
commit83f6043dc8ba291ba6d406f9ba0d98abf053e03a (patch)
treec51065896a02ed6f7a79c8dc8fc61fcc322838a6 /test/data/static.yx
parent6ec0392311952ab4a2d621f39cc082bcc2f5bf9e (diff)
Add tests for static locals
Diffstat (limited to 'test/data/static.yx')
-rw-r--r--test/data/static.yx26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/data/static.yx b/test/data/static.yx
new file mode 100644
index 0000000..8f39a6e
--- /dev/null
+++ b/test/data/static.yx
@@ -0,0 +1,26 @@
+x: int;
+
+/* You can define static local variables and use them */
+foo :: () {
+ static bar := 42;
+ static baz: f32;
+
+ bar = bar * 2;
+}
+
+/* Static locals can shadow other globals */
+bar :: () u128 {
+ static x: u128 = 1'000;
+ return x;
+}
+
+/* Shadowing works in nested functions */
+baz :: () u128 {
+ static x: u128 = 1'000;
+ static y := 42;
+ nested :: () {
+ static x: i16;
+ x = 16;
+ }
+ return x;
+}