summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/bugs/extension-lifetime.slang41
-rw-r--r--tests/diagnostics/extension-visibility-a.slang17
-rw-r--r--tests/diagnostics/extension-visibility-b.slang8
-rw-r--r--tests/diagnostics/extension-visibility-c.slang9
-rw-r--r--tests/diagnostics/extension-visibility.slang18
-rw-r--r--tests/diagnostics/extension-visibility.slang.expected7
-rw-r--r--tests/language-feature/extensions/extension-import-helper.slang13
-rw-r--r--tests/language-feature/extensions/extension-import.slang17
8 files changed, 130 insertions, 0 deletions
diff --git a/tests/bugs/extension-lifetime.slang b/tests/bugs/extension-lifetime.slang
new file mode 100644
index 000000000..38cdf580b
--- /dev/null
+++ b/tests/bugs/extension-lifetime.slang
@@ -0,0 +1,41 @@
+// extension-lifetime.slang
+
+// This test is a regresion test for a bug where `extension`
+// declarations are incorrectly being cached on the declarations
+// they extend, so that an extension of a stdlib type (like `float`)
+// ends up attaching a declaration from one compile request to that
+// type, and then later compile requests that use that stdlib type
+// try to look up through that extension even though (1) that
+// shouldn't make sense semantically, and (2) that extension will
+// have been deallocated when its parent compile request was
+// destroyed.
+//
+// This test relies on the fact that our test runner uses a single
+// slang compilation session (which loads the stdlib code) across
+// multiple compilation tests. We can thus make this file contain
+// two identical tests, with the knowledge that the second one
+// will lead to the bad/crashing behavior if the first one ran
+// and did a Bad Thing.
+
+//TEST:SIMPLE:
+//TEST:SIMPLE:
+
+interface IThing
+{
+ float getThing();
+}
+
+extension float : IThing
+{
+ float getThing() { return this; }
+}
+
+float getThing<T : IThing>(T value)
+{
+ return value.getThing();
+}
+
+float test( float value )
+{
+ return getThing(value);
+}
diff --git a/tests/diagnostics/extension-visibility-a.slang b/tests/diagnostics/extension-visibility-a.slang
new file mode 100644
index 000000000..97e4ef85c
--- /dev/null
+++ b/tests/diagnostics/extension-visibility-a.slang
@@ -0,0 +1,17 @@
+// extension-visibility-a.slang
+
+interface IThing
+{
+ int getValue();
+}
+
+// Note: not implementing the interface here!
+struct MyThing
+{
+ int value;
+}
+
+int helper<T : IThing>(T thing)
+{
+ return thing.getValue();
+} \ No newline at end of file
diff --git a/tests/diagnostics/extension-visibility-b.slang b/tests/diagnostics/extension-visibility-b.slang
new file mode 100644
index 000000000..7848f2a56
--- /dev/null
+++ b/tests/diagnostics/extension-visibility-b.slang
@@ -0,0 +1,8 @@
+// extension-visibility-b.slang
+
+import extension_visibility_a;
+
+extension MyThing : IThing
+{
+ int getValue() { return value; }
+}
diff --git a/tests/diagnostics/extension-visibility-c.slang b/tests/diagnostics/extension-visibility-c.slang
new file mode 100644
index 000000000..2d7a5224d
--- /dev/null
+++ b/tests/diagnostics/extension-visibility-c.slang
@@ -0,0 +1,9 @@
+// extension-visibility-c.slang
+
+import extension_visibility_a;
+import extension_visibility_b;
+
+int works(MyThing thing)
+{
+ return helper(thing);
+}
diff --git a/tests/diagnostics/extension-visibility.slang b/tests/diagnostics/extension-visibility.slang
new file mode 100644
index 000000000..029b16b86
--- /dev/null
+++ b/tests/diagnostics/extension-visibility.slang
@@ -0,0 +1,18 @@
+// extension-visibility.slang
+
+// Confirm that visibility of `extensions` is
+// correctly scoped via `import`.
+
+//DIAGNOSTIC_TEST:SIMPLE:
+
+import extension_visibility_a;
+
+// Note: not importing b:
+// import extension_visibility_b;
+
+import extension_visibility_c;
+
+int shouldntWork(MyThing thing)
+{
+ return helper(thing);
+}
diff --git a/tests/diagnostics/extension-visibility.slang.expected b/tests/diagnostics/extension-visibility.slang.expected
new file mode 100644
index 000000000..217dfa188
--- /dev/null
+++ b/tests/diagnostics/extension-visibility.slang.expected
@@ -0,0 +1,7 @@
+result code = -1
+standard error = {
+tests/diagnostics/extension-visibility.slang(17): error 39999: could not specialize generic for arguments of type (MyThing)
+tests/diagnostics/extension-visibility-a.slang(14): note 39999: see declaration of func helper<T>(T) -> int
+}
+standard output = {
+}
diff --git a/tests/language-feature/extensions/extension-import-helper.slang b/tests/language-feature/extensions/extension-import-helper.slang
new file mode 100644
index 000000000..c1a652645
--- /dev/null
+++ b/tests/language-feature/extensions/extension-import-helper.slang
@@ -0,0 +1,13 @@
+// extension-import-helper.slang
+
+//TEST_IGNORE_FILE:
+
+interface IThing
+{
+ float getValue();
+}
+
+extension float : IThing
+{
+ float getValue() { return this; }
+} \ No newline at end of file
diff --git a/tests/language-feature/extensions/extension-import.slang b/tests/language-feature/extensions/extension-import.slang
new file mode 100644
index 000000000..c5d415a53
--- /dev/null
+++ b/tests/language-feature/extensions/extension-import.slang
@@ -0,0 +1,17 @@
+// extension-import.slang
+
+// Confirm that visibility of extensions through `import` is working.
+
+//TEST:SIMPLE:
+
+import extension_import_helper;
+
+float test<T : IThing>(T value)
+{
+ return value.getValue();
+}
+
+float id(float x)
+{
+ return test(x);
+} \ No newline at end of file