summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/nested-optional.slang
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-06-04 13:05:58 -0700
committerGitHub <noreply@github.com>2025-06-04 13:05:58 -0700
commit812e478989e27983b8dea7ab11964de751654ba2 (patch)
treee6db6def9c7896ee48c5fe42926856644e81c0e6 /tests/language-feature/nested-optional.slang
parentb9dc21d362f65f22bc707bede733a9537b80460a (diff)
Make interface types non c-style in Slang2026. (#7260)
* Make interface types non c-style. * Make Optional<T> work with autodiff and existential types. * Fix. * patch behind slang 2026. * Fix warnings. * cleanup. * Fix tests. * Fix. * Fix com interface lowering. * Add comment to test. * regenerate command line reference * Add test for passing `none` to autodiff function. * Fix recording of `getDynamicObjectRTTIBytes`. * Fix nested Optional types. --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'tests/language-feature/nested-optional.slang')
-rw-r--r--tests/language-feature/nested-optional.slang35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/language-feature/nested-optional.slang b/tests/language-feature/nested-optional.slang
new file mode 100644
index 000000000..8fdeac33b
--- /dev/null
+++ b/tests/language-feature/nested-optional.slang
@@ -0,0 +1,35 @@
+//TEST:INTERPRET(filecheck=CHECK):
+
+Optional<Optional<int>> getNone() { return none; }
+
+void main()
+{
+ Optional<Optional<Optional<int>>> val = Optional<Optional<int>>(5);
+ Optional<Optional<Optional<int>>> defaultVal1 = none;
+ Optional<Optional<Optional<int>>> defaultVal2 = getNone();
+
+ // CHECK: 8
+ printf("%d\n", sizeof(val));
+
+ // CHECK: success
+ if (defaultVal1.hasValue == defaultVal2.hasValue)
+ {
+ printf("success\n");
+ }
+ else
+ {
+ printf("failure\n");
+ }
+
+ // CHECK: value: 5
+ if (let x = val)
+ {
+ if (let y = x)
+ {
+ if (let z = y)
+ {
+ printf("value: %d\n", z);
+ }
+ }
+ }
+} \ No newline at end of file