summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2020-06-05 19:38:43 -0700
committerYong He <yonghe@outlook.com>2020-06-05 19:43:30 -0700
commit956ede9be7d7b798ce719a7ac6a3be3f472f6db7 (patch)
tree8972b17c7f66e17e6f1f639277065aa983cf16f1 /source
parent7d4432ba5ca007b18dfa6e0c19b4598e42c1e505 (diff)
Filter lookup results from interfaces in `visitMemberExpr`.
Fixes #1377
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-check-expr.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp
index 307ec6316..7adda8c77 100644
--- a/source/slang/slang-check-expr.cpp
+++ b/source/slang/slang-check-expr.cpp
@@ -1826,10 +1826,38 @@ namespace Slang
//
expr->baseExpression = maybeOpenExistential(expr->baseExpression);
- // TODO: Handle the case of an overloaded base expression
+ // Handle the case of an overloaded base expression
// here, in case we can use the name of the member to
// disambiguate which of the candidates is meant, or if
// we can return an overloaded result.
+ if (auto overloadedExpr = as<OverloadedExpr>(expr->baseExpression))
+ {
+ if (overloadedExpr->base)
+ {
+ // If a member (dynamic or static) lookup result contains both the actual definition
+ // and the interface definition obtained from inheritance, we want to filter out
+ // the interface definitions.
+ LookupResult filteredLookupResult;
+ for (auto lookupResult : overloadedExpr->lookupResult2)
+ {
+ bool shouldRemove = false;
+ if (lookupResult.declRef.getParent().as<InterfaceDecl>())
+ shouldRemove = true;
+ if (!shouldRemove)
+ {
+ filteredLookupResult.items.add(lookupResult);
+ }
+ }
+ if (filteredLookupResult.items.getCount() == 1)
+ filteredLookupResult.item = filteredLookupResult.items.getFirst();
+ expr->baseExpression = createLookupResultExpr(
+ expr->name,
+ filteredLookupResult,
+ overloadedExpr->base,
+ overloadedExpr->loc);
+ }
+ // TODO: handle other cases of OverloadedExpr that need filtering.
+ }
auto & baseType = expr->baseExpression->type;