diff options
| -rw-r--r-- | source/slang/slang-reflection-api.cpp | 17 | ||||
| -rw-r--r-- | tools/slang-unit-test/unit-test-function-lookup-resolution.cpp | 3 |
2 files changed, 17 insertions, 3 deletions
diff --git a/source/slang/slang-reflection-api.cpp b/source/slang/slang-reflection-api.cpp index 95dcc6249..c5d39859e 100644 --- a/source/slang/slang-reflection-api.cpp +++ b/source/slang/slang-reflection-api.cpp @@ -3471,10 +3471,21 @@ SLANG_API SlangReflectionDecl* spReflectionFunction_asDecl(SlangReflectionFuncti SLANG_API char const* spReflectionFunction_GetName(SlangReflectionFunction* inFunc) { auto func = convertToFunc(inFunc); - if (!func) - return nullptr; + if (func) + return getText(func.getDecl()->getName()).getBuffer(); - return getText(func.getDecl()->getName()).getBuffer(); + // If convertToFunc failed, this might be an overloaded function. + // Try to get the name from the first overload candidate. + auto overloadedFunc = convertToOverloadedFunc(inFunc); + if (overloadedFunc && overloadedFunc->lookupResult2.items.getCount() > 0) + { + auto firstOverload = overloadedFunc->lookupResult2.items[0].declRef; + if (auto funcDeclRef = firstOverload.as<FunctionDeclBase>()) + { + return getText(funcDeclRef.getDecl()->getName()).getBuffer(); + } + } + return nullptr; } SLANG_API SlangReflectionType* spReflectionFunction_GetResultType(SlangReflectionFunction* inFunc) diff --git a/tools/slang-unit-test/unit-test-function-lookup-resolution.cpp b/tools/slang-unit-test/unit-test-function-lookup-resolution.cpp index 539c9ac48..c88ca7760 100644 --- a/tools/slang-unit-test/unit-test-function-lookup-resolution.cpp +++ b/tools/slang-unit-test/unit-test-function-lookup-resolution.cpp @@ -75,6 +75,9 @@ SLANG_UNIT_TEST(functionLookupResolution) auto func1 = layout->findFunctionByNameInType(type, "method"); SLANG_CHECK_ABORT(func1->isOverloaded()); SLANG_CHECK(func1->getOverloadCount() == 3); + // Test that overloaded function containers return the correct name + SLANG_CHECK(func1->getName() != nullptr); + SLANG_CHECK(String(func1->getName()) == "method"); if (func1->isOverloaded()) { List<slang::FunctionReflection*> candidates; |
