diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2020-12-02 14:12:51 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-02 14:12:51 -0800 |
| commit | ad5dda9261bae63e32bcb914b109fcb5c92faf25 (patch) | |
| tree | 97ffa786c6fc03586c112745a12f6373dde252d1 /source | |
| parent | ae222bf4fa131b8b86dd0662b32214eb161ace1a (diff) | |
Fix [mutating] generic methods (#1618)
Slang generates code that turns the implicit `this` parameter of a method into an explicit parameter. The logic that decides whether that parameter should be `inout` is a bit involved, and there was a bug where a generic method would lead to the use of an `in` modifier (the default) and override the `inout` modifier that was requested by the method itself.
This change fixes the logic to treat generic declarations in the parent chain of a leaf method as having no bearing on whether an implicit `this` parameter should be `inout` or not.
A test case is included that breaks with the old behavior, and demonstrates that a generic `[mutating]` method can now work correctly.
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index fefec805c..b2a7529c5 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -2231,6 +2231,14 @@ ParameterDirection getThisParamDirection(Decl* parentDecl, ParameterDirection de return defaultDirection; } + // A parent generic declaration should not change the + // mutating-ness of the inner declaration. + // + if( as<GenericDecl>(parentDecl) ) + { + return defaultDirection; + } + // For now we make any `this` parameter default to `in`. // return kParameterDirection_In; |
