diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2020-07-24 18:12:41 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-24 18:12:41 -0700 |
| commit | 87940a649e3b4f757905015de95225d57ec2f27c (patch) | |
| tree | 189ec1c515bd1180822e8887817c0f235a51c617 /tests/diagnostics/interfaces | |
| parent | 261fe7587d7413070a4e0f29e1a1bb7b0d2b5429 (diff) | |
Fix bugs related to mutating implementations of interface methods (#1461)
There are two main bug fixes here:
* We were failing to diagnose when code calls a `[mutating]` method on a value that doesn't support mutation (that is an r-value instead of an l-value).
* We had a bug in the synthesis logic for interface requirements where we used the *result* type of the requirement in place of each of the *parameter* types.
The second bug made synthesis often produce incorrect signatures with `void` parameters.
The first bug meant that even though a `[mutating]` method should not be able to satisfy a non-`[mutating]` method (and we had code to enforce this for the "exact match" case), when we go on to try and synthesize a non-`[mutating]` method that satisfies the requirement by delegating to the user-written one, it would end up succeeding, because nothing was stopping a non-`[mutating]` method from calling a `[mutating]` one.
In each case this code adds a fix and a test case to confirm it.
Diffstat (limited to 'tests/diagnostics/interfaces')
| -rw-r--r-- | tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang | 42 | ||||
| -rw-r--r-- | tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang.expected | 6 |
2 files changed, 48 insertions, 0 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 new file mode 100644 index 000000000..2dbe45ccb --- /dev/null +++ b/tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang @@ -0,0 +1,42 @@ +// mutating-impl-of-non-mutating-req.slang + +//DIAGNOSTIC_TEST:SIMPLE:-target hlsl -entry main + +interface IThing +{ + int processValue(int inValue); +} + +struct Counter : IThing +{ + int state; + + [mutating] int processValue(int inValue) + { + int result = state; + state += inValue; + return state; + } +} + +int helper<T : IThing>(T thing, int value) +{ + return thing.processValue(value); +} + +int test(int value) +{ + Counter counter = { value }; + return helper(counter, value); +} + +cbuffer C +{ + int gValue; +} + +[shader("fragment")] +int main() : SV_Target +{ + return test(gValue); +}
\ No newline at end of file diff --git a/tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang.expected b/tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang.expected new file mode 100644 index 000000000..922a6c826 --- /dev/null +++ b/tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang.expected @@ -0,0 +1,6 @@ +result code = -1 +standard error = { +tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang(10): error 38100: type 'Counter' does not provide required interface member 'processValue' +} +standard output = { +} |
