summaryrefslogtreecommitdiffstats
path: root/tests/diagnostics
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-07-10 21:14:16 -0700
committerGitHub <noreply@github.com>2025-07-11 04:14:16 +0000
commit90c34e3db4fdc7be79c62bd91905a2a84bbd673e (patch)
treea8ccf3c2dbfe5f1faa646bf91e41d9a12a66c804 /tests/diagnostics
parent7764b83d24d341334ca7c1693cae2472be8f8d99 (diff)
Ensure generic constraints are checked before inner extension. (#7685)
* Ensure generic constraints are checked before inner extension. * Add warning for non-standard generic extension. * Fix tests. * Fix test. * Ban interface types from equality constraints. * Fix.
Diffstat (limited to 'tests/diagnostics')
-rw-r--r--tests/diagnostics/generic-constraint-equality-right-hand-side.slang36
-rw-r--r--tests/diagnostics/non-standard-extension.slang17
2 files changed, 53 insertions, 0 deletions
diff --git a/tests/diagnostics/generic-constraint-equality-right-hand-side.slang b/tests/diagnostics/generic-constraint-equality-right-hand-side.slang
new file mode 100644
index 000000000..c49fe2035
--- /dev/null
+++ b/tests/diagnostics/generic-constraint-equality-right-hand-side.slang
@@ -0,0 +1,36 @@
+//TEST:SIMPLE(filecheck=CHECK):
+interface IGen<A>
+{
+ associatedtype TB;
+ int getVal();
+}
+
+interface Wrapper<A>
+{}
+
+struct Foo1<A> : IGen<A>
+{
+ typealias TB = Wrapper<A>; // `Wrapper<int>` also fails.
+ int val = 0;
+ int getVal()
+ {
+ return val;
+ }
+}
+
+struct Logic<A1, C1 : IGen<A1>>
+{
+ int val = 0;
+}
+
+extension<A, C1> Logic<A, C1>
+ where C1 : IGen<A>
+ //CHECK: ([[# @LINE+1]]): error 30404:
+ where C1.TB == Wrapper<int>
+{
+ [mutating]
+ void setVal(int dataIn)
+ {
+ val = dataIn;
+ }
+}
diff --git a/tests/diagnostics/non-standard-extension.slang b/tests/diagnostics/non-standard-extension.slang
new file mode 100644
index 000000000..d6a4350a4
--- /dev/null
+++ b/tests/diagnostics/non-standard-extension.slang
@@ -0,0 +1,17 @@
+//TEST:SIMPLE(filecheck=CHECK): -warnings-as-errors 30856
+
+interface ICompatibleWith<T> {}
+interface IBase {}
+struct INT : IBase {}
+struct FLOAT : IBase {}
+
+extension<EX : IBase> EX : ICompatibleWith<INT> {}
+extension<EY : IBase> EY : ICompatibleWith<FLOAT> {}
+
+struct VECTOR<T> {}
+
+// CHECK: ([[# @LINE+1]]): error 30856: the extension is non-standard
+extension<T, U : ICompatibleWith<T>> VECTOR<U> : ICompatibleWith<VECTOR<T>> {}
+
+void main()
+{} \ No newline at end of file