summaryrefslogtreecommitdiffstats
path: root/tests/language-feature
diff options
context:
space:
mode:
authorRonan <ro.cailleau@gmail.com>2025-09-30 08:22:50 +0200
committerGitHub <noreply@github.com>2025-09-30 06:22:50 +0000
commitee5adb87050ae7c0b96056a67dddc5d48174e695 (patch)
tree917893600575e8d0bba7d40d4e872ecc13d217fd /tests/language-feature
parenta6deb5ed82cb8fc6b4f4c5c5fee264e09f97ff89 (diff)
canonical type equality constraint (#8445)
Fixes #8439 When checked, generic type equality constraints types are now in a canonical order, allowing for a commutative type equality operator. --------- Co-authored-by: Mukund Keshava <mkeshava@nvidia.com>
Diffstat (limited to 'tests/language-feature')
-rw-r--r--tests/language-feature/generics/type-equality-cononical.slang87
1 files changed, 87 insertions, 0 deletions
diff --git a/tests/language-feature/generics/type-equality-cononical.slang b/tests/language-feature/generics/type-equality-cononical.slang
new file mode 100644
index 000000000..4eb682b10
--- /dev/null
+++ b/tests/language-feature/generics/type-equality-cononical.slang
@@ -0,0 +1,87 @@
+//TEST:SIMPLE(filecheck=CHECK):
+//TEST:INTERPRET(filecheck=ICHECK):
+
+interface MyInterface
+{
+ associatedtype CompatibilityClass;
+
+ __generic <Other : MyInterface>
+ This f(Other other) where Other::CompatibilityClass == This::CompatibilityClass;
+
+ __generic <Other : MyInterface>
+ This g(Other other) where This::CompatibilityClass == Other::CompatibilityClass;
+
+ CompatibilityClass toCompat();
+};
+
+struct MyCompatibilityClass {};
+
+__generic <T>
+struct MyStruct : MyInterface
+{
+ typealias CompatibilityClass = MyCompatibilityClass;
+
+ __generic <Other : MyInterface>
+ This f(Other other) where CompatibilityClass == Other::CompatibilityClass
+ {
+ return this;
+ }
+
+ __generic <Other : MyInterface>
+ This g(Other other) where MyCompatibilityClass == Other::CompatibilityClass
+ {
+ return this;
+ }
+
+ CompatibilityClass toCompat()
+ {
+ return MyCompatibilityClass();
+ }
+};
+
+struct TestInt : MyInterface
+{
+ typealias CompatibilityClass = int;
+ int value;
+
+ __init(int v)
+ {
+ value = v;
+ }
+
+ __generic <Other : MyInterface>
+ This f(Other other) where CompatibilityClass == Other::CompatibilityClass
+ {
+ return this;
+ }
+
+ __generic <Other : MyInterface>
+ This g(Other other) where int == Other::CompatibilityClass
+ {
+ return this;
+ }
+
+ int toCompat()
+ {
+ return value;
+ }
+}
+
+__generic <T : MyInterface>
+void test(T t)
+ where int == T::CompatibilityClass
+{
+ printf("Success x %d!", t.toCompat());
+}
+
+void main()
+{
+ TestInt t = TestInt(12);
+ test(t);
+}
+
+// CHECK-NOT: 30402
+// CHECK-NOT: 30404
+// CHECK-NOT: 30405
+
+// ICHECK: Success x 12! \ No newline at end of file