From 0d26dbaad90f5eac604e148971d14e552bf9d5b8 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 22 Jul 2025 09:03:05 -0700 Subject: 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. --- source/slang/slang.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'source') 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(checkedTerm)) + { + // Check if all candidates are function references + bool allAreFunctions = true; + for (auto item : overloadedExpr->lookupResult2.items) + { + if (!as(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(resolvedTerm)) -- cgit v1.2.3