summaryrefslogtreecommitdiff
path: root/tests/diagnostics
diff options
context:
space:
mode:
Diffstat (limited to 'tests/diagnostics')
-rw-r--r--tests/diagnostics/generic-constraint-forward-reference.slang16
-rw-r--r--tests/diagnostics/generic-constraint-forward-reference.slang.expected14
2 files changed, 30 insertions, 0 deletions
diff --git a/tests/diagnostics/generic-constraint-forward-reference.slang b/tests/diagnostics/generic-constraint-forward-reference.slang
new file mode 100644
index 000000000..08a6c3478
--- /dev/null
+++ b/tests/diagnostics/generic-constraint-forward-reference.slang
@@ -0,0 +1,16 @@
+//DIAGNOSTIC_TEST:SIMPLE:
+// Test forward references in generic constraints
+
+interface IFloat {}
+interface IFoo<T : IFloat> {}
+interface IBar<T, U> {}
+
+// Test case 1: Simple forward reference in interface constraint
+void test1<Foo : IFoo<T>, T : IFloat>() {}
+
+// Test case 2: Multiple forward references in a single constraint
+void test2<A : IBar<B, C>, B : IFloat, C : IFloat>() {}
+
+// Valid case that should NOT produce our error:
+// Test case 3: Correct order - type parameter declared before use
+void test3<T : IFloat, Foo : IFoo<T>>() {}
diff --git a/tests/diagnostics/generic-constraint-forward-reference.slang.expected b/tests/diagnostics/generic-constraint-forward-reference.slang.expected
new file mode 100644
index 000000000..5c6b2707b
--- /dev/null
+++ b/tests/diagnostics/generic-constraint-forward-reference.slang.expected
@@ -0,0 +1,14 @@
+result code = -1
+standard error = {
+tests/diagnostics/generic-constraint-forward-reference.slang(9): error 30117: generic constraint for parameter 'Foo' references type parameter 'T' before it is declared
+void test1<Foo : IFoo<T>, T : IFloat>() {}
+ ^~~~
+tests/diagnostics/generic-constraint-forward-reference.slang(12): error 30117: generic constraint for parameter 'A' references type parameter 'B' before it is declared
+void test2<A : IBar<B, C>, B : IFloat, C : IFloat>() {}
+ ^~~~
+tests/diagnostics/generic-constraint-forward-reference.slang(12): error 30117: generic constraint for parameter 'A' references type parameter 'C' before it is declared
+void test2<A : IBar<B, C>, B : IFloat, C : IFloat>() {}
+ ^~~~
+}
+standard output = {
+}