summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-04-26 10:10:17 -0400
committerGitHub <noreply@github.com>2022-04-26 10:10:17 -0400
commit66ad0072821b58318c6dc5d2d64c966e312951dd (patch)
tree1d28f0dcf23ca9ac40f4fdd0b92eb5a55b170df1 /source
parentb69b0e43e27ec94c0397774db804b4077b062b21 (diff)
Overloaded name lookup fix (#2199)
* #include an absolute path didn't work - because paths were taken to always be relative. * Fix for overloaded name lookup. * Small improvements.
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-lookup.cpp36
1 files changed, 34 insertions, 2 deletions
diff --git a/source/slang/slang-lookup.cpp b/source/slang/slang-lookup.cpp
index e3093a3db..a77478ccb 100644
--- a/source/slang/slang-lookup.cpp
+++ b/source/slang/slang-lookup.cpp
@@ -752,6 +752,31 @@ static void _lookUpMembersInValue(
return _lookUpMembersInType(astBuilder, name, valueType, request, ioResult, breadcrumbs);
}
+// True if the declaration is of an overloadable variety
+// (ie can have multiple definitions with the same name)
+//
+// For example functions are overloadable, but variables are (typically) not.
+static bool _isDeclOverloadable(Decl* decl)
+{
+ // If it's a generic strip off, to get to inner decl type
+ while (auto genericDecl = as<GenericDecl>(decl))
+ {
+ decl = genericDecl->inner;
+ }
+
+ // TODO(JS): Do we need to special case around ConstructorDecl? or AccessorDecl?
+ // It seems not as they are both function-like and potentially overloadable
+
+ // If it's callable, it's a function-like and so overloadable
+ if (auto callableDecl = as<CallableDecl>(decl))
+ {
+ SLANG_UNUSED(callableDecl);
+ return true;
+ }
+
+ return false;
+}
+
static void _lookUpInScopes(
ASTBuilder* astBuilder,
Name* name,
@@ -912,9 +937,16 @@ static void _lookUpInScopes(
if (result.isValid())
{
- // If we've found a result in this scope, then there
+ // If it's overloaded or the decl we have is of an overloadable type then we just keep going
+ if (result.isOverloaded() ||
+ _isDeclOverloadable(result.item.declRef.getDecl()))
+ {
+ continue;
+ }
+
+ // If we've found a result in this scope (and it's not overloadable), then there
// is no reason to look further up (for now).
- return;
+ break;
}
}