summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/core.meta.slang4
-rw-r--r--source/slang/slang-check-overload.cpp18
-rw-r--r--tests/language-feature/generics/variadic-partial-inference.slang25
3 files changed, 44 insertions, 3 deletions
diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang
index 919c21473..67fb201fe 100644
--- a/source/slang/core.meta.slang
+++ b/source/slang/core.meta.slang
@@ -156,6 +156,8 @@ interface IInteger : IArithmetic, ILogical
int64_t toInt64();
uint toUInt();
uint64_t toUInt64();
+ __init(int val);
+ __init(int64_t val);
}
interface IFloat : IArithmetic, IDifferentiable
@@ -220,7 +222,7 @@ interface __BuiltinSignedArithmeticType : __BuiltinArithmeticType {}
/// A type that can represent integers
[sealed]
[builtin]
-interface __BuiltinIntegerType : __BuiltinArithmeticType
+interface __BuiltinIntegerType : __BuiltinArithmeticType, IInteger
{}
/// A type that can represent non-integers
diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp
index 743d518af..6d376dba3 100644
--- a/source/slang/slang-check-overload.cpp
+++ b/source/slang/slang-check-overload.cpp
@@ -466,8 +466,22 @@ namespace Slang
Val* val = nullptr;
if (aa >= matchedArgs.getCount())
{
- // If we run out of matched args, we will just create an empty pack.
- val = m_astBuilder->getTypePack(ArrayView<Type*>());
+ if (allowPartialGenericApp)
+ {
+ // If we have run out of arguments and the decl allows
+ // partial specialization, then we don't apply any more
+ // checks at this step. We will instead attempt to
+ // *infer* an argument at this position at a later
+ // stage.
+ //
+ candidate.flags |= OverloadCandidate::Flag::IsPartiallyAppliedGeneric;
+ break;
+ }
+ else
+ {
+ // Otherwise, we will just create an empty pack.
+ val = m_astBuilder->getTypePack(ArrayView<Type*>());
+ }
}
else
{
diff --git a/tests/language-feature/generics/variadic-partial-inference.slang b/tests/language-feature/generics/variadic-partial-inference.slang
new file mode 100644
index 000000000..003d22424
--- /dev/null
+++ b/tests/language-feature/generics/variadic-partial-inference.slang
@@ -0,0 +1,25 @@
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -output-using-type
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cpu -shaderobj -output-using-type
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -shaderobj -output-using-type
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+void aggregate(inout int v, int u)
+{
+ v = v * u;
+}
+
+T test<T:IInteger, each U : IInteger>(T t, expand each U u)
+{
+ int v = 1;
+ expand aggregate(v, (each u).toInt());
+ return t + T(v);
+}
+
+[numthreads(1, 1, 1)]
+void computeMain()
+{
+ // CHECK: 11
+ outputBuffer[0] = test<int>(5, 1, 2, 3);
+} \ No newline at end of file