From ad5dda9261bae63e32bcb914b109fcb5c92faf25 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Wed, 2 Dec 2020 14:12:51 -0800 Subject: 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. --- source/slang/slang-lower-to-ir.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source') 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(parentDecl) ) + { + return defaultDirection; + } + // For now we make any `this` parameter default to `in`. // return kParameterDirection_In; -- cgit v1.2.3