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 /source/slang/slang-check-decl.cpp | |
| 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 'source/slang/slang-check-decl.cpp')
| -rw-r--r-- | source/slang/slang-check-decl.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 2879d7fa2..3cc0fd0f5 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -1576,7 +1576,7 @@ namespace Slang // auto synParamDecl = m_astBuilder->create<ParamDecl>(); synParamDecl->nameAndLoc = paramDeclRef.getDecl()->nameAndLoc; - synParamDecl->type.type = resultType; + synParamDecl->type.type = paramType; // We need to add the parameter as a child declaration of // the method we are building. @@ -1599,7 +1599,12 @@ namespace Slang // if any. // ThisExpr* synThis = nullptr; - if( !requiredMemberDeclRef.getDecl()->hasModifier<HLSLStaticModifier>() ) + if( requiredMemberDeclRef.getDecl()->hasModifier<HLSLStaticModifier>() ) + { + auto synStaticModifier = m_astBuilder->create<HLSLStaticModifier>(); + synFuncDecl->modifiers.first = synStaticModifier; + } + else { // For a non-`static` requirement, we need a `this` parameter. // |
