diff options
| author | Yong He <yonghe@outlook.com> | 2024-12-30 23:39:07 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-30 23:39:07 -0800 |
| commit | cc1b96d91d8875bf727079d58fbf78af1135f505 (patch) | |
| tree | 593a6aae09e2710390ac34fdeb84614872ac9d5f /tests | |
| parent | 88e221bad60ce20087fe2f8a85d506be36a6e6ca (diff) | |
Check mismatching method parameter direction against interface declaration. (#5964)
Diffstat (limited to 'tests')
4 files changed, 93 insertions, 3 deletions
diff --git a/tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang b/tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang index 2dbe45ccb..3c7c874c9 100644 --- a/tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang +++ b/tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang @@ -1,7 +1,6 @@ // mutating-impl-of-non-mutating-req.slang -//DIAGNOSTIC_TEST:SIMPLE:-target hlsl -entry main - +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK):-target hlsl -entry main interface IThing { int processValue(int inValue); @@ -10,7 +9,8 @@ interface IThing struct Counter : IThing { int state; - + + // CHECK: ([[# @LINE+1]]): error 38105: [mutating] int processValue(int inValue) { int result = state; diff --git a/tests/language-feature/interfaces/argument-direction-mismatch.slang b/tests/language-feature/interfaces/argument-direction-mismatch.slang new file mode 100644 index 000000000..cf9d99fdd --- /dev/null +++ b/tests/language-feature/interfaces/argument-direction-mismatch.slang @@ -0,0 +1,37 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv + +public interface ITest { + public void testIn(int a); + public void testOut(out int b); +}; + +public struct TestImpl : ITest { + // CHECK: ([[# @LINE + 1]]): error 38105 + public void testIn(out int a) { + a = 5; + } + // CHECK: ([[# @LINE + 1]]): error 38105 + public void testOut(int b) { + b = 6; + } +} + +RWStructuredBuffer<int> output; + +void doSomething<T>(T data) where T : ITest { + int a = 516; + data.testIn(a); + int b = 687; + data.testOut(b); + + output[0] = a; + output[1] = b; +} + +[shader("compute")] +[numthreads(1,1,1)] +void computeMain() +{ + TestImpl data; + doSomething(data); +}
\ No newline at end of file diff --git a/tests/language-feature/modules/wrapper-inout.slang b/tests/language-feature/modules/wrapper-inout.slang new file mode 100644 index 000000000..5b7b9fbce --- /dev/null +++ b/tests/language-feature/modules/wrapper-inout.slang @@ -0,0 +1,29 @@ +//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK): -output-using-type + +public interface ITest { + public int testDir(inout int a); +}; + +public struct TestImpl : ITest { + public int testDir(inout int a) { + int oldA = a; + a = 5; + return a; + } +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=output +RWStructuredBuffer<int> output; + +public struct Test : ITest = TestImpl; + +[shader("compute")] +[numthreads(1,1,1)] +void computeMain() +{ + Test data; + int a = 516; + int b = data.testDir(a); + // CHECK: 5 + output[0] = b; +}
\ No newline at end of file diff --git a/tests/language-feature/modules/wrapper-property.slang b/tests/language-feature/modules/wrapper-property.slang new file mode 100644 index 000000000..cfd9798b7 --- /dev/null +++ b/tests/language-feature/modules/wrapper-property.slang @@ -0,0 +1,24 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv + +//CHECK: OpEntryPoint + +public interface ITest { + public property int val; +}; + +public struct TestImpl : ITest { + public int val; +} + +public struct Test : ITest = TestImpl; + +StructuredBuffer<Test> data; +RWStructuredBuffer<int> output; + +[shader("compute")] +[numthreads(1,1,1)] +void computeMain() +{ + int val = data[0].val; + output[0] = val; +}
\ No newline at end of file |
