summaryrefslogtreecommitdiff
path: root/tests/diagnostics/variable-redeclaration.slang
diff options
context:
space:
mode:
Diffstat (limited to 'tests/diagnostics/variable-redeclaration.slang')
-rw-r--r--tests/diagnostics/variable-redeclaration.slang54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/diagnostics/variable-redeclaration.slang b/tests/diagnostics/variable-redeclaration.slang
new file mode 100644
index 000000000..bbd6a07c0
--- /dev/null
+++ b/tests/diagnostics/variable-redeclaration.slang
@@ -0,0 +1,54 @@
+// variable-redeclaration.slang
+
+//DIAGNOSTIC_TEST:SIMPLE:
+
+
+// This test confirms that the compiler produces
+// suitable diagnostics when variables are redeclared
+// in a given scope.
+
+// Global variables, including shader parameters
+
+static int gA;
+
+static Texture2D gA;
+
+// Local variables
+
+int testLocalRedeclaration(int x)
+{
+ int y = x;
+ int y = x;
+}
+
+int testLocalShadowing(int x)
+{
+ int y = x;
+ {
+ // Because this declaration is in an inner
+ // scope it should shadow the existing `y`
+ // rather than conflcit with it.
+ //
+ // TODO: It would be reasonable for the
+ // compiler to warn on this sort of code.
+ //
+ int y = x;
+ }
+}
+
+// Structure fields
+
+struct S
+{
+ int f;
+ float f;
+}
+
+// Function parameter list
+
+int testParameterRedeclaration(
+ int size,
+ float size)
+{
+ return size;
+}