From 90c34e3db4fdc7be79c62bd91905a2a84bbd673e Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 10 Jul 2025 21:14:16 -0700 Subject: 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. --- ...neric-constraint-equality-right-hand-side.slang | 36 ++++++++++++++++++++++ tests/diagnostics/non-standard-extension.slang | 17 ++++++++++ 2 files changed, 53 insertions(+) create mode 100644 tests/diagnostics/generic-constraint-equality-right-hand-side.slang create mode 100644 tests/diagnostics/non-standard-extension.slang (limited to 'tests/diagnostics') 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 +{ + associatedtype TB; + int getVal(); +} + +interface Wrapper +{} + +struct Foo1 : IGen +{ + typealias TB = Wrapper; // `Wrapper` also fails. + int val = 0; + int getVal() + { + return val; + } +} + +struct Logic> +{ + int val = 0; +} + +extension Logic + where C1 : IGen + //CHECK: ([[# @LINE+1]]): error 30404: + where C1.TB == Wrapper +{ + [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 {} +interface IBase {} +struct INT : IBase {} +struct FLOAT : IBase {} + +extension EX : ICompatibleWith {} +extension EY : ICompatibleWith {} + +struct VECTOR {} + +// CHECK: ([[# @LINE+1]]): error 30856: the extension is non-standard +extension> VECTOR : ICompatibleWith> {} + +void main() +{} \ No newline at end of file -- cgit v1.2.3