From ce4386b02b15c9ab55be25030e358770c4825fb6 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 6 Dec 2024 19:41:43 -0800 Subject: [PATCH] Fix. --- source/slang/slang-check-expr.cpp | 27 ++++++++++++++------------- source/slang/slang-check-impl.h | 9 ++++++--- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index a856c58b41..1f2776ba01 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -2954,7 +2954,10 @@ Expr* SemanticsExprVisitor::visitInvokeExpr(InvokeExpr* expr) auto operatorName = getName("()"); bool needDeref = false; - expr->functionExpr = maybeInsertImplicitOpForMemberBase(expr->functionExpr, needDeref); + expr->functionExpr = maybeInsertImplicitOpForMemberBase( + expr->functionExpr, + CheckBaseContext::Member, + needDeref); LookupResult lookupResult = lookUpMember( m_astBuilder, @@ -4063,7 +4066,7 @@ void SemanticsExprVisitor::maybeCheckKnownBuiltinInvocation(Expr* invokeExpr) } } -Expr* SemanticsVisitor::MaybeDereference(Expr* inExpr) +Expr* SemanticsVisitor::maybeDereference(Expr* inExpr, CheckBaseContext checkBaseContext) { Expr* expr = inExpr; for (;;) @@ -4079,6 +4082,8 @@ Expr* SemanticsVisitor::MaybeDereference(Expr* inExpr) } else if (auto ptrType = as(baseType)) { + if (checkBaseContext == CheckBaseContext::Subscript) + return expr; elementType = QualType(ptrType->getValueType()); elementType.isLeftValue = true; } @@ -4761,7 +4766,7 @@ Expr* SemanticsExprVisitor::visitStaticMemberExpr(StaticMemberExpr* expr) expr->baseExpression = CheckTerm(expr->baseExpression); // Not sure this is needed -> but guess someone could do - expr->baseExpression = MaybeDereference(expr->baseExpression); + expr->baseExpression = maybeDereference(expr->baseExpression, CheckBaseContext::Member); // If the base of the member lookup has an interface type // *without* a suitable this-type substitution, then we are @@ -4789,9 +4794,12 @@ Expr* SemanticsVisitor::lookupMemberResultFailure( return expr; } -Expr* SemanticsVisitor::maybeInsertImplicitOpForMemberBase(Expr* baseExpr, bool& outNeedDeref) +Expr* SemanticsVisitor::maybeInsertImplicitOpForMemberBase( + Expr* baseExpr, + CheckBaseContext checkBaseContext, + bool& outNeedDeref) { - auto derefExpr = MaybeDereference(baseExpr); + auto derefExpr = maybeDereference(baseExpr, checkBaseContext); if (derefExpr != baseExpr) outNeedDeref = true; @@ -4852,14 +4860,7 @@ Expr* SemanticsVisitor::checkBaseForMemberExpr( auto baseExpr = inBaseExpr; baseExpr = CheckTerm(baseExpr); - // Do not insert implicit deref/open existential for Ptr.operator[]. - if (checkBaseContext == CheckBaseContext::Subscript && - as(unwrapModifiedType(baseExpr->type.type))) - { - outNeedDeref = false; - return baseExpr; - } - return maybeInsertImplicitOpForMemberBase(baseExpr, outNeedDeref); + return maybeInsertImplicitOpForMemberBase(baseExpr, checkBaseContext, outNeedDeref); } Expr* SemanticsVisitor::checkGeneralMemberLookupExpr(MemberExpr* expr, Type* baseType) diff --git a/source/slang/slang-check-impl.h b/source/slang/slang-check-impl.h index f4ab40fd9d..460e87cb9b 100644 --- a/source/slang/slang-check-impl.h +++ b/source/slang/slang-check-impl.h @@ -2654,8 +2654,6 @@ struct SemanticsVisitor : public SemanticsContext // // - Expr* MaybeDereference(Expr* inExpr); - Expr* CheckMatrixSwizzleExpr( MemberExpr* memberRefExpr, Type* baseElementType, @@ -2706,9 +2704,14 @@ struct SemanticsVisitor : public SemanticsContext CheckBaseContext checkBaseContext, bool& outNeedDeref); + Expr* maybeDereference(Expr* inExpr, CheckBaseContext checkBaseContext); + /// Prepare baseExpr for use as the base of a member expr. /// This include inserting implicit open-existential operations as needed. - Expr* maybeInsertImplicitOpForMemberBase(Expr* baseExpr, bool& outNeedDeref); + Expr* maybeInsertImplicitOpForMemberBase( + Expr* baseExpr, + CheckBaseContext checkBaseContext, + bool& outNeedDeref); Expr* lookupMemberResultFailure( DeclRefExpr* expr,