summaryrefslogtreecommitdiffstats
path: root/source/slang/slang.cpp
diff options
context:
space:
mode:
authorCopilot <198982749+Copilot@users.noreply.github.com>2025-07-22 09:03:05 -0700
committerGitHub <noreply@github.com>2025-07-22 09:03:05 -0700
commit0d26dbaad90f5eac604e148971d14e552bf9d5b8 (patch)
treec45813fdb1d613817fca5673b000097ac83c097e /source/slang/slang.cpp
parentf25e5a89f00bcecacee4f09901d5cfdc1be341c6 (diff)
Fix findFunctionByNameInType to preserve functions with different signatures (#7827)
findFunctionByNameInType was only returning one function when multiple functions existed with the same name but different signatures. This broke reflection functionality for extension methods. Fix the issue by changing findDeclFromStringInType by not calling maybeResolveOverloadedExpr if checkedTerm is overloaded functions. We still call maybeResolveOverloadedExpr when any candidates in the overloaded list is not DeclRefExpr referencing a function.
Diffstat (limited to 'source/slang/slang.cpp')
-rw-r--r--source/slang/slang.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 29ca2328b..839ba7938 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -3039,7 +3039,34 @@ Expr* ComponentType::findDeclFromStringInType(
}
auto checkedTerm = visitor.CheckTerm(expr);
- auto resolvedTerm = visitor.maybeResolveOverloadedExpr(checkedTerm, mask, sink);
+
+ // Check if checkedTerm is overloaded functions and avoid resolving if so
+ // to preserve all function overloads with different signatures
+ Expr* resolvedTerm = checkedTerm;
+ if (auto overloadedExpr = as<OverloadedExpr>(checkedTerm))
+ {
+ // Check if all candidates are function references
+ bool allAreFunctions = true;
+ for (auto item : overloadedExpr->lookupResult2.items)
+ {
+ if (!as<FunctionDeclBase>(item.declRef.getDecl()))
+ {
+ allAreFunctions = false;
+ break;
+ }
+ }
+
+ // If not all are functions, resolve the overload as usual
+ if (!allAreFunctions)
+ {
+ resolvedTerm = visitor.maybeResolveOverloadedExpr(checkedTerm, mask, sink);
+ }
+ }
+ else
+ {
+ // Not overloaded, resolve as usual
+ resolvedTerm = visitor.maybeResolveOverloadedExpr(checkedTerm, mask, sink);
+ }
if (auto overloadedExpr = as<OverloadedExpr>(resolvedTerm))