summaryrefslogtreecommitdiff
path: root/source/slang/slang-lookup.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-06-13 22:13:00 -0700
committerGitHub <noreply@github.com>2025-06-13 22:13:00 -0700
commit6a23949f07f4eba38086b656e7073ce3bf8cd2fe (patch)
tree132bbe330b6027d323c74175686d006605e4da6d /source/slang/slang-lookup.cpp
parente72b3325663ab6d4bb791742574b031f0df6328a (diff)
Allow interface methods to have default implementations. (#7439)
Diffstat (limited to 'source/slang/slang-lookup.cpp')
-rw-r--r--source/slang/slang-lookup.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/source/slang/slang-lookup.cpp b/source/slang/slang-lookup.cpp
index d03d763b8..604cee2b7 100644
--- a/source/slang/slang-lookup.cpp
+++ b/source/slang/slang-lookup.cpp
@@ -977,6 +977,35 @@ static void _lookUpInScopes(
nullptr);
}
+ if (auto defaultImplDecl = as<InterfaceDefaultImplDecl>(containerDecl))
+ {
+ // If we are checking an interface default method implementation,
+ // we should look up members from implicit `this` whose type is the explicit `This`
+ // generic parameter, and skip looking up in the interface decl itself.
+
+ // Instead of looking up in the interface decl itself, we should
+ // look up in the `This` type instead.
+ if (getText(name) != "This")
+ {
+ BreadcrumbInfo breadcrumb;
+ breadcrumb.kind = LookupResultItem::Breadcrumb::Kind::This;
+ breadcrumb.thisParameterMode = thisParameterMode;
+ breadcrumb.declRef = DeclRef<Decl>(defaultImplDecl->thisTypeDecl);
+ breadcrumb.prev = nullptr;
+ Type* type = DeclRefType::create(astBuilder, breadcrumb.declRef);
+ _lookUpMembersInType(astBuilder, name, type, request, result, &breadcrumb);
+ }
+
+ // We need to skip looking up in the interface decl itself, since we are
+ // looking up in the implicit `this` type.
+ for (; scope && !as<InterfaceDecl>(scope->containerDecl); scope = scope->parent)
+ {
+ // We need to skip looking up in the interface decl itself, since we are
+ // looking up in the implicit `this` type.
+ }
+ break;
+ }
+
// Before we proceed up to the next outer scope to perform lookup
// again, we need to consider what the current scope tells us
// about how to interpret uses of implicit `this` or `This`. For