summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/slang-check-overload.cpp16
-rw-r--r--tests/autodiff/differential-type-constructor.slang25
-rw-r--r--tests/autodiff/differential-type-constructor.slang.expected.txt6
3 files changed, 46 insertions, 1 deletions
diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp
index 6180ccda8..703771e6e 100644
--- a/source/slang/slang-check-overload.cpp
+++ b/source/slang/slang-check-overload.cpp
@@ -2093,7 +2093,21 @@ namespace Slang
typeCheckingCache->resolvedOperatorOverloadCache[key] = *context.bestCandidate;
return CompleteOverloadCandidate(context, *context.bestCandidate);
}
- else if (auto typetype = as<TypeType>(funcExprType))
+
+ // If absolutely no viable candidates were extracted from the overloaded expression,
+ // we may be dealing with a composite type or an overloaded expression with composite types.
+ //
+
+ auto typeExpr = funcExpr;
+ if (auto overloadedExpr = as<OverloadedExpr>(funcExpr))
+ {
+ if (overloadedExpr->lookupResult2.isValid() && overloadedExpr->lookupResult2.isOverloaded())
+ {
+ typeExpr = maybeResolveOverloadedExpr(overloadedExpr, LookupMask::type, nullptr);
+ }
+ }
+
+ if (auto typetype = as<TypeType>(typeExpr->type))
{
// We allow a special case when `funcExpr` represents a composite type,
// in which case we will try to construct the type via memberwise assignment from the arguments.
diff --git a/tests/autodiff/differential-type-constructor.slang b/tests/autodiff/differential-type-constructor.slang
new file mode 100644
index 000000000..9afff878d
--- /dev/null
+++ b/tests/autodiff/differential-type-constructor.slang
@@ -0,0 +1,25 @@
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
+
+struct MyStruct: IDifferentiable
+{
+ float a;
+ int b;
+}
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
+{
+ {
+ var dp = diffPair(MyStruct(), MyStruct.Differential());
+
+ outputBuffer[0] = dp.d.a;
+
+ var dp2 = diffPair<MyStruct>(MyStruct(), MyStruct.Differential(1.f));
+
+ outputBuffer[1] = dp2.d.a;
+ }
+} \ No newline at end of file
diff --git a/tests/autodiff/differential-type-constructor.slang.expected.txt b/tests/autodiff/differential-type-constructor.slang.expected.txt
new file mode 100644
index 000000000..d9eca87b2
--- /dev/null
+++ b/tests/autodiff/differential-type-constructor.slang.expected.txt
@@ -0,0 +1,6 @@
+type: float
+0.000000
+1.000000
+0.000000
+0.000000
+0.000000