diff options
| author | Yong He <yonghe@outlook.com> | 2025-07-10 21:14:16 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-11 04:14:16 +0000 |
| commit | 90c34e3db4fdc7be79c62bd91905a2a84bbd673e (patch) | |
| tree | a8ccf3c2dbfe5f1faa646bf91e41d9a12a66c804 /tests | |
| parent | 7764b83d24d341334ca7c1693cae2472be8f8d99 (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')
6 files changed, 110 insertions, 0 deletions
diff --git a/tests/bugs/gh-5140.slang b/tests/bugs/gh-5140.slang index 23d9b3a23..bf18b04a6 100644 --- a/tests/bugs/gh-5140.slang +++ b/tests/bugs/gh-5140.slang @@ -3,6 +3,8 @@ //TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +#pragma warning(disable:30856) + public interface A<T: IFloat> { } 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 diff --git a/tests/language-feature/extensions/generic-extension-2.slang b/tests/language-feature/extensions/generic-extension-2.slang index 2728a73d6..d56455e3d 100644 --- a/tests/language-feature/extensions/generic-extension-2.slang +++ b/tests/language-feature/extensions/generic-extension-2.slang @@ -1,4 +1,6 @@ //TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj + +#pragma warning(disable:30856) interface IFoo<T> { T getFirst(); diff --git a/tests/language-feature/extensions/generic-extension-5.slang b/tests/language-feature/extensions/generic-extension-5.slang new file mode 100644 index 000000000..e6466d614 --- /dev/null +++ b/tests/language-feature/extensions/generic-extension-5.slang @@ -0,0 +1,52 @@ +//TEST:INTERPRET(filecheck=CHECK): +interface IGen<A> +{ + associatedtype TB; + TB getVal(); +} + +struct Foo1<A> : IGen<A> +{ + typealias TB = int; + int val = 0; + TB getVal() + { + return val; + } +} + +struct Foo2<A> : IGen<A> +{ + typealias TB = int; + int val = 0; + TB getVal() + { + return val; + } +} + +struct Logic<A1, C1 : IGen<A1>, C2 : IGen<A1>> +{ + int val = 0; +} + +extension<A, C1, C2> Logic<A, C1, C2> + where C1 : IGen<A> + where C2 : IGen<A> + where C1.TB == C2.TB +{ + [mutating] + void setVal(int dataIn) + { + val = dataIn; + } +} + +void main() +{ + Logic<int, Foo1<int>, Foo2<int>> logic; + logic.setVal(42); + int result = logic.val; + printf("Result: %d\n", result); + // CHECK: Result: 42 +}
\ No newline at end of file diff --git a/tests/language-feature/overloaded-subscript.slang b/tests/language-feature/overloaded-subscript.slang index 68ad1111a..e928e97ec 100644 --- a/tests/language-feature/overloaded-subscript.slang +++ b/tests/language-feature/overloaded-subscript.slang @@ -13,6 +13,7 @@ interface IRWBuf<T> : IBuf<T> void write(int x, T v); } +#pragma warning(disable:30856) extension<T, U : IBuf<T>> U { __subscript(int x) -> T { get { return read(x); } } |
