Skip to content

Commit

Permalink
Fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
csyonghe committed Dec 7, 2024
1 parent 3fb927d commit ce4386b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
27 changes: 14 additions & 13 deletions source/slang/slang-check-expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 (;;)
Expand All @@ -4079,6 +4082,8 @@ Expr* SemanticsVisitor::MaybeDereference(Expr* inExpr)
}
else if (auto ptrType = as<PtrType>(baseType))
{
if (checkBaseContext == CheckBaseContext::Subscript)
return expr;
elementType = QualType(ptrType->getValueType());
elementType.isLeftValue = true;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<PtrType>(unwrapModifiedType(baseExpr->type.type)))
{
outNeedDeref = false;
return baseExpr;
}
return maybeInsertImplicitOpForMemberBase(baseExpr, outNeedDeref);
return maybeInsertImplicitOpForMemberBase(baseExpr, checkBaseContext, outNeedDeref);
}

Expr* SemanticsVisitor::checkGeneralMemberLookupExpr(MemberExpr* expr, Type* baseType)
Expand Down
9 changes: 6 additions & 3 deletions source/slang/slang-check-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2654,8 +2654,6 @@ struct SemanticsVisitor : public SemanticsContext
//
//

Expr* MaybeDereference(Expr* inExpr);

Expr* CheckMatrixSwizzleExpr(
MemberExpr* memberRefExpr,
Type* baseElementType,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ce4386b

Please sign in to comment.