summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-check-expr.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-check-expr.cpp
parente72b3325663ab6d4bb791742574b031f0df6328a (diff)
Allow interface methods to have default implementations. (#7439)
Diffstat (limited to 'source/slang/slang-check-expr.cpp')
-rw-r--r--source/slang/slang-check-expr.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp
index 9f5c1dc2e..4c6bf98d2 100644
--- a/source/slang/slang-check-expr.cpp
+++ b/source/slang/slang-check-expr.cpp
@@ -5346,6 +5346,12 @@ Expr* SemanticsExprVisitor::visitThisExpr(ThisExpr* expr)
}
return expr;
}
+ else if (auto defaultImplDecl = as<InterfaceDefaultImplDecl>(containerDecl))
+ {
+ expr->type.type =
+ DeclRefType::create(m_astBuilder, DeclRef<Decl>(defaultImplDecl->thisTypeDecl));
+ return expr;
+ }
#if 0
else if (auto aggTypeDecl = as<AggTypeDecl>(containerDecl))
{
@@ -5401,7 +5407,12 @@ Expr* SemanticsExprVisitor::visitThisTypeExpr(ThisTypeExpr* expr)
expr->type.type = thisTypeType;
return expr;
}
-
+ else if (auto defaultImplDecl = as<InterfaceDefaultImplDecl>(containerDecl))
+ {
+ expr->type.type =
+ DeclRefType::create(m_astBuilder, DeclRef<Decl>(defaultImplDecl->thisTypeDecl));
+ return expr;
+ }
scope = scope->parent;
}
@@ -5409,6 +5420,22 @@ Expr* SemanticsExprVisitor::visitThisTypeExpr(ThisTypeExpr* expr)
return CreateErrorExpr(expr);
}
+Expr* SemanticsExprVisitor::visitThisInterfaceExpr(ThisInterfaceExpr* expr)
+{
+ auto scope = expr->scope;
+
+ auto containerDecl = findParentInterfaceDecl(scope->containerDecl);
+
+ // ThisInterfaceExpr can only be synthesized by the compiler during parsing
+ // an interface decl with default implementation, so container must always
+ // be an interface decl.
+ SLANG_ASSERT(containerDecl);
+ expr->declRef =
+ createDefaultSubstitutionsIfNeeded(m_astBuilder, this, getDefaultDeclRef(containerDecl));
+ expr->type = m_astBuilder->getTypeType(DeclRefType::create(m_astBuilder, expr->declRef));
+ return expr;
+}
+
Expr* SemanticsExprVisitor::visitCastToSuperTypeExpr(CastToSuperTypeExpr* expr)
{
// CastToSuperType is effectively a struct field.