summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-check-conversion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-check-conversion.cpp')
-rw-r--r--source/slang/slang-check-conversion.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/source/slang/slang-check-conversion.cpp b/source/slang/slang-check-conversion.cpp
index c135ada8d..85040dc55 100644
--- a/source/slang/slang-check-conversion.cpp
+++ b/source/slang/slang-check-conversion.cpp
@@ -498,6 +498,27 @@ namespace Slang
toInitializerListExpr->type = QualType(toType);
toInitializerListExpr->args = coercedArgs;
+ // Wrap initalizer list args if we're creating a non-differentiable struct within a
+ // differentiable function.
+ //
+ if (auto func = getParentFuncOfVisitor())
+ {
+ if (func->findModifier<DifferentiableAttribute>() &&
+ !isTypeDifferentiable(toType))
+ {
+ for (auto &arg : toInitializerListExpr->args)
+ {
+ if (isTypeDifferentiable(arg->type.type))
+ {
+ auto detachedArg = m_astBuilder->create<DetachExpr>();
+ detachedArg->inner = arg;
+ detachedArg->type = arg->type;
+ arg = detachedArg;
+ }
+ }
+ }
+ }
+
*outToExpr = toInitializerListExpr;
}